0
votes

I have a React frontend, which is querying Solr (through Python/Django) with the users search text and filter selections. Solr returns the product results with facets, dynamically updating which facets are shown and the count of products in each facet (or facet.pivot).

I am trying to allow the user to multi-select two filters in a single filter group. The issue is that as soon as the user selects a filter, the Solr query is narrowed down and the neighboring filter is not shown any more. For example, once the user selects "Men's", an updated facet group is returned, and "Women's" is not an option anymore.

An attempted solution was to store the old state and re-inject it into the new filter group. So if a user selected "Men's" and queried Solr, the filter group would still show up ["Men's", "Women's"]:

if (specs_update) { 
    json.specs[this.state.spec_clicked_info.group] = this.state.spec_clicked_info.specs; 
}

This doesn't work. Imagine that the user decided to select both "Men's" and "Women's", then he selected "T-shirt" (there are only men's t-shirts in our store). If he were to now deselect "Men's", the query to Solr would still include the now stale choice of "Women's" and display zero results to the user.

1
So what would you like to do in that case? Remove Women's as a filter or T-Shirt? The first case is usually implemented by tagging your filters and the using excludes in facets accordingly.MatsLindh
So I have implemented tagging and excludes to allow for neighboring facets to still show once clicked. Correct me if I'm wrong: I still need to manually remove "Women's" from user selection when user clicks T-shirt so it isn't included in Solr query?Avi Kaminetzky
In other words, this is an elegant solution for having Solr display unselected filters with counts, however front end work is still required. I must keep track that the user selected T-shirt, therefore facet count of women's is now 0 and should be deselected and remove from future queries.Avi Kaminetzky

1 Answers

0
votes

Per MatsLindh's comment I have implemented tagging and excluding filters to allow for multi select on a specific facet group.

The first step is to keep track in the frontend of which facet groups currently have any facet selected. On the Python end, that info is used to apply a tag on the fq parameter (for example, fq={!tag=style}casual) and a corresponding exclude in facet.field (for example, facet.field={!ex=style}style).

This strategy works for facet.pivot's as well, but with some tweaking. Say you had a 3-level deep tree of 'company, collection, sub_collection', but you only want to apply tagging & excluding to collection and sub_collection. You can't apply a tag to one part of the facet.pivot, so you would need to control the top level company facets from the frontend (correct me if I'm wrong).

Some examples:

https://stackoverflow.com/a/39803098/4822174

http://yonik.com/multi-select-faceting/

However, we still need to account for the fact the frontend thinks that the current selection is still gender:Women's (see example in question). We can achieve this by doing a check on the backend that the new facets returned contain all components of the users query, and if not, remove them:

for spec, spec_arr in current_filter['specs_filter'].items():
    for a_spec in spec_arr:
        for key,value in raw_response['facet_counts']['facet_fields'].items():
            if key == spec and a_spec not in [*value]:
                current_filter['specs_filter'][spec].remove(a_spec)