In my project, we use solr to index a lot of different kind of documents, by example Books and Persons, with some common fields (like the name) and some type-specific fields (like the category, or the group people belong to).
We would like to do queries that can find both books and persons, with for each document type some filters applied. Something like:
- find all Books and Persons with "Jean" in the name and/or content
- but only Books from category "fiction" and "fantasy"
- and only Persons from the group "pangolin"
- everything sorted by score
A very simple way to do that would be:
q = name:jean content:jean
&
fq=
(type:book AND category:(fiction fantasy))
OR
(type:person AND group:pangolin)
But alas, as fq
are cached, I'd prefer something allowing me simpler and so more reusable fq
like :
fq=type:book
,fq=type:person
,fq=category(fiction fantasy)
,fq=group:pangolin
.
Is there a way to tell solr to merge or combine many queries? Something like 'grouping' fq
together.
I read a bit about nested queries with _query_
, but the very few documentation about it makes me think it's not the solution I'm looking for.