Reputation: 563
When querying solr for products I also return the facets. For fields such as category, size, colour, price.
So I do something along the lines of:
solr.search(*:*, **{'start': 0,
'rows': 50,
'defType': 'edismax',
'fq': '(category=Shoes)',
'facet': 'true',
'facet.limit': -1,
'facet.field': ['size', 'colour', 'price'],
'facet.mincount': 0})
If I query for category "Shoes"
I see the possible size, colours and prices which match that category. Now if I add to the filter (colour:Red)
then all the other possible colours will disappear which is logical as its now filtered on the colour but the user might want to choose two colours.
What is the a better/the usual way to achieve this?
Upvotes: 0
Views: 478
Reputation: 52792
You can implement this by adding tags to your fq
's and then excluding those tags when creating the facets. An example is show in Faceting - LocalParameters for Faceting:
To return counts for doctype values that are currently not selected, tag filters that directly constrain doctype, and exclude those filters when faceting on doctype.
q=mainquery&fq=status:public&fq={!tag=dt}doctype:pdf&facet=true&facet.field={!ex=dt}doctype
Filter exclusion is supported for all types of facets. Both the tag and ex local parameters may specify multiple values by separating them with commas.
The implementation would then just OR the different selected values for each filter together in the fq
for that filter (so you get color:red OR color:blue
or color:(red OR blue)
.
Yonik also has an example on his blog that's very close to your use-case, but it uses the same method as shown in the reference manual above.
Upvotes: 2