Updated Facets on Search

I’m building my own faceted search UI based on the fields I’ve marked as facetable/filterable in my Algolia dash (not using InstantSearch). I’m having some difficulty implementing the logic I require when updated the facet values.

Basically, I retrieve all facets (*) when my page loads. From that point, users can either (1) search for terms or (2) filter (using the facet UI). So let’s say I have two facet categories: (1) Store (e.g., Gap, Walmart, Target), and (2) Size (e.g., small, medium, large).

I would like users to be able to select multiple values in the same category (i.e., user should be able to select Gap and Walmart – OR query) and see the results. Search gets executed as soon as the user selects a facet. However, because I retrieve updated facets upon a response from Algolia based on the selected facet, my other facets in that same category disappear.

For example, if I select ‘Gap’, now my search results won’t include ‘Target’ in the facet values. Furthermore, while values within a category should be OR queries, values in different categories should be AND queries (e…g, Macys AND medium).

I’m not sure how best to handle this. One thing I updated in my code to mitigate this is only retrieve facets on initial page load, however this has two shortcomings: (1) I lose facet count updates based on search terms, and (2) Users can no be led into a direction where the search results will come up empty. Any direction would be phenomenal. Thanks!

Hi @spatel783, thanks for reaching out about this. Curious about how are you are implementing this, since not using InstantSearch. Are you using our JS Helper or simply sending in search requests with filters applied?

In either case, you should be able to accomplish disjunctive (“OR”) type faceting. In the case of the Helper you have the ability to addDisjunctiveFacetRefinements and if using the filters parameter, you can specific “AND” or "OR"s between filters of the same type.

Please let us know more about how you are currently trying to accomplish this and we’ll be happy to try to help!