Reputation: 6039
How to do an OR expression that filters to either blank field or a specific value?
This does not seem to do it:
q=(-PrivacyLevel:*) OR PrivacyLevel:2
Thanks
Upvotes: 10
Views: 21937
Reputation: 2005
The solution worked for me is q = -PrivacyLevel:(*) PrivacyLevel:("2")
.
Happy coding.
Upvotes: 0
Reputation: 7657
The answer is to use double negation as suggested by Maurizio In denmark. Mathematically this is identical to the non-negated query, however, Solr only understands the double negated version:
q=-(-PrivacyLevel:2 PrivacyLevel:*)
Note: This also works for filter queries:
fq=-(-PrivacyLevel:2 PrivacyLevel:*)
Upvotes: 8
Reputation: 52779
Checkout SolrQuerySyntax
Pure Negative Queries :-
-field:[* TO *]
finds all documents without a value for field
You can try :-
q=-PrivacyLevel:[* TO *] OR PrivacyLevel:2
Upvotes: 6
Reputation: 431
See also Solr field query (fq) with AND and OR operator for a potential problem and a workaround with negative query.
Upvotes: 1
Reputation: 3512
This should works:
q=(*:* AND -PrivacyLevel:[* TO *]) OR PrivacyLevel:2
Upvotes: 3