Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query Solr for empty field or specific value

Tags:

solr

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

like image 677
Marquez Avatar asked Aug 14 '12 17:08

Marquez


People also ask

What is the difference between Q and FQ in solr?

Standard solr queries use the "q" parameter in a request. Filter queries use the "fq" parameter. The primary difference is that filtered queries do not affect relevance scores; the query functions purely as a filter (docset intersection, essentially).

What is WT in solr?

Solr supports a variety of Response Writers to ensure that query responses can be parsed by the appropriate language or application. The wt parameter selects the Response Writer to be used. The table below lists the most common settings for the wt parameter.

What does FQ mean in solr?

The fq (Filter Query) Parameter The fq parameter defines a query that can be used to restrict the superset of documents that can be returned, without influencing score. It can be very useful for speeding up complex queries, since the queries specified with fq are cached independently of the main query.


1 Answers

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:*)
like image 147
Jack Miller Avatar answered Oct 21 '22 11:10

Jack Miller