lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erick Erickson" <>
Subject Re: Searching for null (empty) fields, how to use -field:[* TO *]
Date Tue, 11 Mar 2008 17:46:11 GMT
You could also think about making a filter, probably when you open
your searcher. You can use TermDocs/TermEnum to find all of the documents
that *do* have entries for your field, assemble those into a filter, then
invert that filter. Keep the filter around and use it whenever you need
to. Perhaps CachingWrapperFilter would help here (although I've never
used the latter).

Another possibility is to index a field only for those documents that
don't have any value for MY_FIELD_NAME. So when indexing a doc, you
have something like
if (has MY_FIELD_NAME) {
   doc.add("MY_FIELD_NAME", <real value>);
} else {
   doc.add("NO_MY_FIELD_NAME", "no");

Now finding docs without your field really is just searching on

Your index would be very slightly bigger in this instance....


On Tue, Mar 11, 2008 at 10:16 AM, thogau <> wrote:

> Hi,
> I browsed the forum searching for a way to make a query that retrieves
> document that do not have any value for a given field (say MY_FIELD_NAME).
> I read several posts advising to use this syntax : -MY_FIELD_NAME:[* TO *]
> However, I am not able to have it working...
> I have 2 documents, the first one has a value for the field MY_FIELD_NAME
> (In Luke, I can see the value) and the second one has no value for it (In
> Luke, I can see &lt;not available&gt;)
> I would expect the query MY_FIELD_NAME:[* TO *] to retrieve the document
> which has a value for the field MY_FIELD_NAME but it doesn't (Nevertheless
> MY_FIELD_NAME:[a* TO z*] retrieves it)
> Also, I would expect the query -MY_FIELD_NAME:[* TO *] to retrieve the
> document which has a NO value for the field MY_FIELD_NAME but it doesn't
> either...
> I guess I am missing something obvious but I am stuck... Anybody can help
> to
> understand what I am doing wrong?
> --
> View this message in context:
> Sent from the Lucene - Java Users mailing list archive at

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message