10

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

1
  • blank or non-existent (i.e: undefined)? Commented Aug 14, 2012 at 21:01

6 Answers 6

8

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:*)
Sign up to request clarification or add additional context in comments.

Comments

6

Checkout SolrQuerySyntax

Pure Negative Queries :-

-field:[* TO *] finds all documents without a value for field

You can try :-

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

2 Comments

A link to the very same answer. How redundant!
3

This should works:

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

Comments

3

This is worked for me:

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

Comments

1

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

Comments

0

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

Happy coding.

2 Comments

**? That is not a valid query term.
* and ** both does the same job. To avoid ambiguity, I edit my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.