'Show all facet values when filtering is applied?

Is there a way to show/get all facets even if filtering on a specific facet value?

Example: Facets "facet" with values "A","B" and "C". User selects A => filter: facet eq 'A'

This gives and result with only facet "A" back (and its count).

But if wer then still want to show all facets (A,B and C) to the user, so the user can add other facetvalues. Say user to select also B.

(And we have "OR"-operation for the filtering for A and B)



Solution 1:[1]

You need two queries to support your requirement.

Imagine your result set has items with three types of color. The color can be red, green and blue. Facets are always generated based on your result set. If you filter by blue, your result set only contains items where the color is blue.

To support your requirement, you need to issue a separate query that does not filter by the selected facet. Your two queries should be something like:

  1. Query for all items: search=*&facet=Color
  2. Query for blue items: search=*&$filter=Color eq 'blue'

As for your second question about OR for filters, this is supported. It's up to your application to generate the appropriate filters.

search=*&$filter=Color eq 'blue' or Color eq 'red'

Or use the search.in syntax if you have many color values. See https://docs.microsoft.com/en-us/azure/search/search-query-odata-search-in-function.

search=*&$filter=search.in(Color, 'blue,red', ',')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dan Gøran Lunde