Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Searching for date range or null/no field in Solr [duplicate]

Tags:

solr

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 *]) 
like image 227
Alistair Doulin Avatar asked Aug 27 '09 21:08

Alistair Doulin


2 Answers

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.

like image 106
Svetlana Avatar answered Sep 20 '22 14:09

Svetlana


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.

like image 35
Sebastien Lorber Avatar answered Sep 18 '22 14:09

Sebastien Lorber