Vulnerability in EPiServer.Forms
So we're looking to rework the way we apply filters and display facets in our search. Within the same facets, we want to use Or (e.g. Color = Blue OR Red). Between facets, we want to use And (e.g. Color = Blue AND Size = Large). While doing this, we also want to maintain counts on every option that should follow a similar pattern of not being affected by same facet selections, and being affected by other facets.
So for an example, say there's 3 products of each color blue and red in every size of small, medium, large (3 blue large, 3 blue med, 3 red small, etc.) With nothing selected, the counts should be 9, 9 and 6, 6, 6 respectively. If you select Blue, only the 9 Blue products would be displayed, but the facet counts would update to 9, 9 and 3, 3, 3. If you then also select Medium, only the 3 Blue Medium products should be returned, and the counts should update to 3, 3 and 3, 3, 3. Lastly if you then also select Red, the 6 Medium products should appear, and the counts should become 3, 3 and 6, 6, 6.
If that's still confusing, newegg's search appears to be exactly what we're looking for so you can see it in action there.
We've tried a few different options, but can't seem to find one that gets both the counts and the returned results right at the same time. If anyone can offer ideas how to achieve this using Find, I'd be glad to hear. Thanks.
Have you found any good solution to this? I'm in the exact same situation and can't seem to find a intuitive solution.
As far as I'm aware, you would have to use a multi search for this. It will perform two searches but only one request/response to/from the search service at least.
If you are using React and Redux or something similar, you could manage to do this in one search request. If no facet filters are applied (like in first request to search page), you could use .FilterHits() and when filters are applied you could use .Filter(). FilterHits will always give you the counts for all facets.
The reducer could then update facet count on all facets but the selected one, based on response from the server. If all filters are cleared, you would have to refresh all facets from the server.
I ended up using only one single search using this great extension from Henrik Lindström. https://www.lindstromhenrik.com/facet-filtering-with-episerver-find/
That extension gave me the ability to create a solution based on the ideas in this post. https://medium.com/swlh/faceted-navigation-for-e-commerce-with-elasticsearch-dbf82bdeb7d4
Another similar example can be found in the Elastic search docs. https://www.elastic.co/guide/en/elasticsearch/reference/current/filter-search-results.html