krinn
krinn

Reputation: 892

Apache Solr - OR in filter query

Is it possible to search (with apache Solr) for items which are in one of few categories using filter query, e.g. items in category 'computers' OR 'phones'

When I want to search for items in category computers AND phones I type:

select/?q=...&fq=cat:computers&fq=cat:phones

but it is possible to use OR instead of AND?

Upvotes: 42

Views: 65291

Answers (2)

Bill Dueber
Bill Dueber

Reputation: 2706

A filter query is just a query -- as complex as you'd like. So, you can certainly build up a query, e.g.,

fq=(cat1:val1 OR cat2:val2 OR (cat3:(val3 AND val4)))

...or whatever.

The only difference between a filter query and a plain-old query (besides memory and caching issues, which you might want to also think about) is that a filter query doesn't affect the relevancy scores at all. But in terms of complexity, you can do whatever you want.

Upvotes: 53

Jayendra
Jayendra

Reputation: 52779

You can use

fq=cat:(computers OR phones)

Upvotes: 72

Related Questions