Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solr filter query including NOT and OR

For a filter query in Solr, I need to include all documents not of a certain type, plus any documents of that type which have a value in a certain field.

I tried this:

fq=(-type_id:(A) OR content:(['' TO *]))

But it is excluding documents of type_id B, C, etc. which have null content. (type_id is a string field and content is text.)

I have seen this question: Complex SOLR query including NOT and OR and this post about operators: http://robotlibrarian.billdueber.com/2011/12/solr-and-boolean-operators/. I think the syntax I have should be correct. Can anyone see my error?


Update: I am using the LuceneQParser. It parses the filter query above as

-type_id:A content:['' TO *]

It parses the filter query suggested in the comments (-type_id:A OR (content:[* TO *] AND type_id:A)) as

-type_id:A (+content:[* TO *] +type_id:A)

so no results.

like image 322
Kimberly Avatar asked May 24 '13 21:05

Kimberly


1 Answers

The negation needs a complete set to match against it, so your filter should be:

fq=((*:* AND -type_id:A) OR content:(['' TO *]))
like image 164
Johnny Oshika Avatar answered Oct 15 '22 04:10

Johnny Oshika