I've spent hours poking around for a solution to my problem. I've seen people ask questions close to what I'm trying to accomplish, but so far no one seems to be asking the same question. Let me see if I can explain this adequately:
Say I'm a shoe store. On my web site I have three pages: one for men's shoes, one for women's shoes and one for kid's shoes. Let's say my shoe table has the field prod_group. So for the men's page the query would be q=prod_group:men. Now let's say one of the facets I want to provide is brand. q=prod_group:men&filter.field=brand
The issue I'm having is the facet results are showing all brands in my database, not just brands relevant to men's shoes. In other words, I already know that there are zero men's shoes in the "My Little Pony" line. I don't want to display My Little Pony in the brand facet. Setting facet.mincount isn't what I need either. If I run a query q=prod_group:men&fq=color:red&filter.field=brand, the client wants to show the consumer that the brand "Mighty Joe" doesn't have any red shoes so I still need facets with a facet count of 0.
Basically what I'm hoping for is facet results based on the results from the base query. So far the only way I see to accomplish this is to run two queries: the first with just the base query and setting facet.mincount = 1 to get a list of relevant facets and then the actual query with facet.mincount back to 0 so I can figure out when to grey out certain options that are no longer available based on facet choices already made.
Running two queries seems somewhat less than elegant. facet.pivot might help in the long run, but we're still using 3.x and I don't see that changing any time soon. Have I missed some query/schema/configuration option that will do what I need with one query?
You can check for one option called Facet Excluding Filters, which will allow you to return the facets irrespective of the filter applied.
e.g.
you filter on men fq=prod_group:men
with facet.mincount 1 which will return all the brand facets applicable to this filter.
Then when you sub filter on some color fq=color:red
you can get two facets back one with the results and one without the filter using the excluding filters
e.g. fq={!tag=dt}color:red&facet.field={!ex=dt key=nonfilter_brand}brand&facet.field=brand
This will give you both the facets with and without filter using which you can use to grey out the differences the client side. A bit of overhead on the client side, but you just need to perform a single query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With