How to request Solr for an empty field or a specific value

How to make an OR expression that filters an empty field or a specific value?

It doesn't look like this:

q=(-PrivacyLevel:*) OR PrivacyLevel:2

thanks

+6
source share
6 answers

Checkout SolrQuerySyntax

Purely negative requests: -

-field:[* TO *] finds all documents with no field value

You can try :-

q=-PrivacyLevel:[* TO *] OR PrivacyLevel:2

+5
source

The answer is to use the double negation proposed by Maurizio In denmark . Mathematically, this is identical to a non-rejected query, however, Solr only understands the double-negation version:

 q=-(-PrivacyLevel:2 PrivacyLevel:*) 

Note. This also works for filter queries:

 fq=-(-PrivacyLevel:2 PrivacyLevel:*) 
+4
source

This works for me:

 fq=(* -type:[ * TO * ]) || (* +type:company) 
+3
source

This should work:

 q=(*:* AND -PrivacyLevel:[* TO *]) OR PrivacyLevel:2 
+2
source

See also Solr (fq) field query with AND and OR operator for potential problem and workaround with negative query.

+1
source

The solution, q = -PrivacyLevel:(**) PrivacyLevel:("2") for me, is q = -PrivacyLevel:(**) PrivacyLevel:("2") .

Good coding.

0
source

All Articles