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

d-_-b
  • 21,536
  • 40
  • 150
  • 256
Marquez
  • 5,891
  • 3
  • 31
  • 40

6 Answers6

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:*)
Jack Miller
  • 6,843
  • 3
  • 48
  • 66
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

d-_-b
  • 21,536
  • 40
  • 150
  • 256
Jayendra
  • 52,349
  • 4
  • 80
  • 90
3

This should works:

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

This is worked for me:

fq=(* -type:[ * TO * ]) || (* +type:company)
mrvol
  • 2,575
  • 18
  • 21
1

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

Community
  • 1
  • 1
user1533634
  • 431
  • 4
  • 5
0

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

Happy coding.

Bandham Manikanta
  • 1,858
  • 21
  • 21