> Using Solr 1.4 I wanted to construct a query that returns
> documents that
> have a particular field value or are missing the field. The
> first thing I
> came up with was:
> 
> field1:particularvalue OR -field1:[* TO *]
> 
> It turns out the -field1:[* TO *] was being ignored. If
> particularvalue
> wasn't found, for instance, it returned 0 hits.
> 
> Well after a lot of experimentation I found a query that
> works as expected:
> 
> field1:particularvalue OR (*:* AND -field1:[* TO *])
> 
> It seems like a hack though. Am I approaching this the
> wrong way? What's the
> recommended way for doing this type of search?

What you have found/done is correct way of doing this.

"When dealing with Lucene people are strongly encouraged to think in terms of 
MUST, MUST_NOT and SHOULD (which are represented in the query parser as the 
prefixes "+", "-" and the default) instead of in terms of AND, OR, and NOT ... 
Lucene's Boolean Queries (and thus Lucene's QueryParser) is not a strict 
Boolean Logic system, so it's best not to try and think of it like one." [1]

[1] http://search-lucene.com/m/wEUvc10TfyQ/


      

Reply via email to