Juhan
Juhan

Reputation: 1291

IN Equivalent Query In Solr and Solrj

I am using solr5.0.0. I would like to know the equivalent query for IN in solr or solrj.

If I need to query products of different brands, I can use IN clause. If I have brands like dell, sony, samsung. I need to find the product with these brands using Solr and in Java Solrj.

Now I am using this code in Solrj

qry.addFilterQuery("brand:dell OR brand:sony OR brand:samsung");

I know that I can use OR here, but need to know about IN in Solr. And the performance of OR.

Upvotes: 2

Views: 1183

Answers (1)

cheffe
cheffe

Reputation: 9500

As you can read in Solr's wiki about its' query syntax, Solr uses per default a superset of Lucene's Query parser. As you can see when reading both documents, something like IN does not exist. But you can get shorter than the example query you presented.

In case that your default operator is OR you can leave it out from the query. In addition you can make use of Field Grouping.

qry.addFilterQuery("brand:(dell sony samsung)");

In case OR is not your default operator or you are not sure about this, you can employ Local Parameters for the filter query so that OR is enforced. Afterwards you can again make use of Field Grouping.

qry.addFilterQuery("{!q.op=OR}brand:(dell sony samsung)");

Keep in mind that you need to surround a phrase with " to keep the words together

qry.addFilterQuery("{!q.op=OR}brand:(dell sony samsung \"packard bell\")");

Upvotes: 4

Related Questions