You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Paul Taylor <pa...@fastmail.fm> on 2011/12/19 11:05:25 UTC

Query that returns all docs that contain a field

I was looking for a Query that returns all documents that contain a 
particular field, it doesnt matter what the value of the field is just 
that the document contains the field.

Paul



---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


RE: Query that returns all docs that contain a field

Posted by Uwe Schindler <uw...@thetaphi.de>.
Hi,

The filter is called oal.search.FieldValueFilter, to make a Query out of it use ConstantScoreQuery(new FieldValueFilter(...)).

I think it will come in 3.6, unfortunately 3.5 does not contain it (it was added shortly after release by Simon and me, https://issues.apache.org/jira/browse/LUCENE-3593). You can use nightly 3.6 snapshot:
https://builds.apache.org/job/Lucene-3.x/javadoc/all/org/apache/lucene/search/FieldValueFilter.html

Download:
https://builds.apache.org/job/Lucene-3.x/lastSuccessfulBuild/artifact/artifacts/

If you want to use the Bits from FieldCache.getDocsWithField() directly, you have to countercheck IndexReader.isDeleted(), eg.: (Bits.get(doc) && !reader.isDeleted(doc);

Uwe

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: uwe@thetaphi.de


> -----Original Message-----
> From: Paul Taylor [mailto:paul_t100@fastmail.fm]
> Sent: Tuesday, December 20, 2011 8:35 PM
> To: java-user@lucene.apache.org
> Subject: Re: Query that returns all docs that contain a field
> 
> On 20/12/2011 19:27, Uwe Schindler wrote:
> > Hi,
> >
> > No. But the corresponding filter/query does. The bits are just for lookup, if
> you already have a valid document. The remaining bits are undefined (like the
> rest of Fieldcache).
> >
> > Uwe
> >
> Um, I just looked for the query in Javadocs and couldn't find it, what is it called
> ?
> 
> Paul
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Query that returns all docs that contain a field

Posted by Paul Taylor <pa...@fastmail.fm>.
On 20/12/2011 19:27, Uwe Schindler wrote:
> Hi,
>
> No. But the corresponding filter/query does. The bits are just for lookup, if you already have a valid document. The remaining bits are undefined (like the rest of Fieldcache).
>
> Uwe
>
Um, I just looked for the query in Javadocs and couldn't find it, what 
is it called ?

Paul

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Query that returns all docs that contain a field

Posted by Uwe Schindler <uw...@thetaphi.de>.
Hi,

No. But the corresponding filter/query does. The bits are just for lookup, if you already have a valid document. The remaining bits are undefined (like the rest of Fieldcache).

Uwe
--
Uwe Schindler
H.-H.-Meier-Allee 63, 28213 Bremen
http://www.thetaphi.de



Paul Taylor <pa...@fastmail.fm> schrieb:

On 19/12/2011 13:35, Michael McCandless wrote:
> You could also use FieldCache.getDocsWithField; it returns a bit set
> where the bit is set if that document had that field.
>
And would this disregard documents that have been deleted but are still 
in the index

Paul

_____________________________________________

To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Query that returns all docs that contain a field

Posted by Paul Taylor <pa...@fastmail.fm>.
On 19/12/2011 13:35, Michael McCandless wrote:
> You could also use FieldCache.getDocsWithField; it returns a bit set
> where the bit is set if that document had that field.
>
And would this disregard documents that have been deleted but are still 
in the index

Paul

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Query that returns all docs that contain a field

Posted by Paul Taylor <pa...@fastmail.fm>.
On 19/12/2011 13:39, Uwe Schindler wrote:
> Hi,
>
> There is also a Query/Filter based on that FieldCache:
> o.a.l.search.FieldValueFilter, possibly wrapped with ConstantScoreQuery
>
> Uwe
>
>
Okay, thanks for all the options.

Paul

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


RE: Query that returns all docs that contain a field

Posted by Uwe Schindler <uw...@thetaphi.de>.
Hi,

There is also a Query/Filter based on that FieldCache:
o.a.l.search.FieldValueFilter, possibly wrapped with ConstantScoreQuery

Uwe

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: uwe@thetaphi.de


> -----Original Message-----
> From: Michael McCandless [mailto:lucene@mikemccandless.com]
> Sent: Monday, December 19, 2011 2:36 PM
> To: java-user@lucene.apache.org
> Cc: paul_t100@fastmail.fm
> Subject: Re: Query that returns all docs that contain a field
> 
> You could also use FieldCache.getDocsWithField; it returns a bit set where
the
> bit is set if that document had that field.
> 
> Mike McCandless
> 
> http://blog.mikemccandless.com
> 
> On Mon, Dec 19, 2011 at 7:32 AM, Trejkaz <tr...@trypticon.org> wrote:
> > On Mon, Dec 19, 2011 at 9:05 PM, Paul Taylor <pa...@fastmail.fm>
> wrote:
> >> I was looking for a Query that returns all documents that contain a
> >> particular field, it doesnt matter what the value of the field is
> >> just that the document contains the field.
> >
> > If you don't care about performance (or if it runs fast enough
> > already), use a PrefixQuery with "" as the prefix.
> >
> > If you care about performance, add a new field which contains the
> > names of each field in the document, and query on that.
> >
> > TX
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: java-user-help@lucene.apache.org
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Query that returns all docs that contain a field

Posted by Michael McCandless <lu...@mikemccandless.com>.
You could also use FieldCache.getDocsWithField; it returns a bit set
where the bit is set if that document had that field.

Mike McCandless

http://blog.mikemccandless.com

On Mon, Dec 19, 2011 at 7:32 AM, Trejkaz <tr...@trypticon.org> wrote:
> On Mon, Dec 19, 2011 at 9:05 PM, Paul Taylor <pa...@fastmail.fm> wrote:
>> I was looking for a Query that returns all documents that contain a
>> particular field, it doesnt matter what the value of the field is just that
>> the document contains the field.
>
> If you don't care about performance (or if it runs fast enough
> already), use a PrefixQuery with "" as the prefix.
>
> If you care about performance, add a new field which contains the
> names of each field in the document, and query on that.
>
> TX
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Query that returns all docs that contain a field

Posted by Trejkaz <tr...@trypticon.org>.
On Mon, Dec 19, 2011 at 9:05 PM, Paul Taylor <pa...@fastmail.fm> wrote:
> I was looking for a Query that returns all documents that contain a
> particular field, it doesnt matter what the value of the field is just that
> the document contains the field.

If you don't care about performance (or if it runs fast enough
already), use a PrefixQuery with "" as the prefix.

If you care about performance, add a new field which contains the
names of each field in the document, and query on that.

TX

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org