Aizaz
Aizaz

Reputation: 79

Can I apply facets on the entire solr result instead of the filtered solr result?

Let's say I have a collection of solr documents:

{'id': 1, 'title': 'shirt', 'brand': 'adidas'},
{'id': 2, 'title': 'shirt2', 'brand': 'adidas'},
{'id': 3, 'title': 'shirt', 'brand': 'nike'},
{'id': 4, 'title': 'shirt', 'brand': 'puma'}

Now if I try to apply faceting on this with facet.field=brand, I will get the following

{'adidas': 2, 'nike': 1, 'puma': 1}

In addition, if I apply a filter brand:adidas, I get the following for faceting:

{'adidas': 2, 'nike': 0, 'puma': 0}

Is it possible to still get the count of documents returned by solr before the filtering happened? I would like to still see {'adidas': 2, 'nike': 1, 'puma': 1} regardless of what filters I apply

Upvotes: 0

Views: 29

Answers (1)

MatsLindh
MatsLindh

Reputation: 52832

You can use tagging and excluding filters as shown in the reference guide.

q=yourquery&fq={!tag=brand}brand:adidas&facet=true&facet.field={!ex=brand}brand

The {!ex} instruction will then exclude any filters matching that tag from the active filters when generating the facet results, allowing you to keep the complete set of brands matching the query available as facets.

Upvotes: 1

Related Questions