1

Being new to Lucene I'd like to find documents where a certain field is either within a given range or entirely absent. That is I'd like to combine the results of these two queries:

q=something AND field:[lower TO upper]
q=something AND -field:[* TO *]

Either query gives me the desired result but when I try to combine the two I get nothing:

q=something AND (field:[lower TO upper] OR -field:[* TO *])

something can be a more complex query. Actually, my query will be Solr query from within a Java program in case it makes a difference. How can this be done?

mplwork
  • 1,120
  • 10
  • 21
  • 2
    Check - http://stackoverflow.com/questions/1343794/searching-for-date-range-or-null-no-field-in-solr And http://stackoverflow.com/questions/634765/using-or-and-not-in-solr-query/ – Jayendra Mar 05 '12 at 15:13
  • Thanks a lot. Indeed that works. So the answer is `q=something AND NOT (-field:[lower TO upper] AND field:[* TO *])`. Now I wonder how expensive is such a query? – mplwork Mar 05 '12 at 15:59

1 Answers1

0

This should work as well:

q=( (+something -field:[* TO *]) OR (+something +field:[lower TO upper]) )
David Faber
  • 12,277
  • 2
  • 29
  • 40