Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Filter Queries with OR operation in Solr

Tags:

solr

I need to define multiple Filter Queries in my query but with OR operation. Imagine that there are fq1, fq2 and fq3. Now I would like my final filter query to be :

fq=fq1 AND fq2 OR fq3

Is there any way to handle it in Solr?

like image 411
Reza Avatar asked Dec 01 '11 03:12

Reza


People also ask

What is 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). Follow this answer to receive notifications.

How query all fields in solr?

The correct way is the copyField you have and declaring the field all as the default search field. That's how the examples that ship with Solr out of the box do it. Excellent, adding <str name="df">all</str> to defaults in solrconfig. xml indeed solved this.

What is eDisMax in solr?

The Extended DisMax (eDisMax) query parser is an improved version of the DisMax query parser. In addition to supporting all the DisMax query parser parameters, Extended Dismax: supports the full Lucene query parser syntax. supports queries such as AND, OR, NOT, -, and +.

What is defType in solr?

The defType Parameter The defType parameter selects the query parser that Solr should use to process the main query parameter ( q ) in the request. For example: defType=dismax. If no defType param is specified, then by default, the The Standard Query Parser is used. ( eg: defType=lucene )


2 Answers

It seems that now SOLR (>4.5) supports these type of queries, i.e.

fq=(field1:value1 OR field2:value2)

like image 93
Zouzias Avatar answered Sep 24 '22 05:09

Zouzias


This is not possible in Solr. It would be great if you could define your filter queries and then separately specify the boolean logic that should be applied between them.

A few years ago I created a Jira issue hoping to see this get added.

like image 34
brian519 Avatar answered Sep 22 '22 05:09

brian519