I want to perform a search on a text field in Solr. I want to return all matches in a range or where there is no value. The two searches word independently:
myfield:[start TO finish] -myfield:[* TO *]
The first returns all matches in the range. The second returns all matches that have no value for the "myfield" field. The problem is combining these two.
This returns no matches:
myfield:[start TO finish] OR -myfield:[* TO *]
This returns matches between start and finish, but not null entries:
myfield:[start TO finish] OR (-myfield:[* TO *])
The solution from Mauricio Scheffer worked for me until I've included it into full query. The query itself may contain up to three fields with ranges and somewhere in the middle Solr failed to process it. I have managed to solve it with next query:
(myfield:[start TO finish] OR (*:* NOT myfield:[* TO *]))
It woked even in my complex query, so maybe it will help someone else.
I agree with Mauricio Scheffer solution.
If that can help, I transformed my initial query:
DocSource:"P" OR ( DocSource:"E" AND (MyDate:[NOW TO *] OR -MyDate:[* TO *] ) )
To
DocSource:"P" OR ( DocSource:"E" AND -( -MyDate:[* TO NOW] AND MyDate:[* TO *] ) )
The first query didn't run as expected in Solr 4.1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With