Solr creates multi-select facet counts for me as described here:
I also have various predefined searches that allow a user to browse the catalog. Here is one such example and its query parameters:
q=*:*
fq={!tag=g}genre:western
facet=on
facet.field={!ex=g}genre
facet.mincount=1
facet.limit=50
With this search I get up to 50 genre values in the facet list. I then go through and mark which values were selected by the user; western in this case. This works well except when western is pushed out of the top 50. So I manually add it to the list to make a total of 51. This way the user can see that it is indeed selected. The problem is I have to leave the count for western blank because I don't know it.
Is there a way to get counts for specific facet values such as western in this case? Or another approach to solve this issue?
I am using Solr 4.7.0.
Solr allows you to create a query-based facet count by using the
facet.query
parameter. When creating a filter query (fq
) that's based on a facet field value, I now create a corresponding facet query:and add it to the rest of my parameters:
The facet_queries object will now be populated in the solr response:
Regardless of what is returned in the
facet_fields
object, I'm now guaranteed to have a facet count forgenre:western
. With some parsing, facet field counts can be extracted from the facet queries.