42

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?

Ravindra S
  • 6,302
  • 12
  • 70
  • 108
krinn
  • 882
  • 2
  • 10
  • 16

2 Answers2

70

You can use

fq=cat:(computers OR phones)
Jayendra
  • 52,349
  • 4
  • 80
  • 90
  • Hello i have got params={start=1&q=file_content+:+cześć*&wt=javabin&fq=file_create_user:\-1+AND+file_parents_folder:\(341\+AND\+4222\)&version=2&rows=25} status=400 QTime=2 and i have got error Invalid Number: (341 AND 4222) – Łukasz Woźniczka Aug 02 '13 at 07:28
  • would this make it a single key in the filter cache or two different keys in the filter cache (one for computer and one for phone)? – jigar surana Aug 09 '19 at 23:48
  • Single key in filter cache – Yash Agarwal May 23 '23 at 20:23
53

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.

Bill Dueber
  • 2,706
  • 17
  • 16