Manage facet display from the Algolia dashboard
Control the facets to display and their order by sending arenderingContent parameter with your search query.
Your UI must interpret this setting so your users can interact with the index.
The main implementation steps are:
- Configure the attributes to use for faceting on your search index.
- Configure your facet display.
- Build a UI capable of interpreting the
renderingContentsetting. For this step, use InstantSearch library widgets. You can create a UI with other tools but must write the interpretation logic yourself.
Configure facet display from the dashboard
Configure facet display from the dashboard
- Select the Search product icon on your dashboard and then select your index.
- Click the Configuration tab.
- Under the Filtering and Faceting category, click Facet display.
- Click Add facet to display to choose the facets you want to display in your UI.
-
Use the
=icon next to each facet to drag them into the correct position. The order you set here determines how facets display in your UI. -
For each facet, click the pen icon to configure how the engine should display the facet’s values. You can:
- Pin some values at the top of the list if you want to display them first.
- Hide some values from the list entirely.
- Choose how to display the remaining facet values: by count, alphabetically, or only display pinned values.
- To remove a facet from the list and stop displaying it in your UI, click the trash icon.
- Save your changes.
- Since you have a specific partnership with the brand “Lacoste”, you want the brand to always display on top.
- Sizes need to be in a specific order: S, M, L, XL. You may have sizes in different formats in your data, but for the sake of clarity, you only want to display those four. You pin them at the top in the correct order and choose not to display other values
- For colors, you want to display them by count and not pin any specific value.
This approach lets you configure a static facet display.
If you want a more dynamic approach that customizes the display of the facets and values for a specific query or category, see the Merchandising facets.
Configure facet display with the API
Configure facet display with the API
To replicate the dashboard example,
use the API client’s
setSettings method with the following settings applied to your index:Hide facet values
The following example shows three facets:author, brand, and on_sale (in that order).
The author facet is sorted by number of hits, the brand facet is ordered alphabetically, always shows the facet value “Kensington” in the first position (pinned) and never shows the value “Bosch” (hidden). The on_sale facet only shows the pinned true value.
JavaScript
Build the UI with InstantSearch
The simplest way to control facet display is to use InstantSearch. This UI library has built-in widgets that understand therenderingContent data returned by searches.
This data includes everything you need to show facets how you want.
Facet display requirements for InstantSearch
To make your UI compatible with the facet display feature:- Vue InstantSearch version 4.1.0 or later (see Upgrade guide)
- Add refinement widgets for the different facets.
- Add a
dynamicWidgetscontainer around the widgets you want to sort. - In those widgets, remove any custom
sortByor setfacetOrderingtotrue.
Vue
Optimize dynamic widget network requests
Algolia automatically mounts the appropriate widgets for the search results.Vue
Widget limitation
This applies to Vue InstantSearch version 4.3 or later.
-
Add an
applicable_facetsfacet to every object:JSON -
Configure the dynamic widget so it doesn’t ask for all facets. Many of them will be hidden anyway because of the 1,000 facet limit. To do this, set
facetsto[](empty).Vue -
Ensure that
applicable_facetsis always requested. Such as from a hidden menu:Vue -
Use
transformItemsofdynamicWidgetsto useapplicable_facetsfor dynamic widget rendering:Vue
Build the UI without InstantSearch
If you aren’t using InstantSearch to build your UI, you need to build frontend logic to:- Interpret the
renderingContentparameter returned along search results, - Order facets and values based on your interpretation of the
renderingContentparameter values.
- Reading the facet order
- Reading the facet value order
Read the facet order
If you hardcode the list of facets to display on a page, you can read that fromresult.renderingContent.facetOrdering.facets.order (all keys are optional).
This is the list of attributes that you chose to display and can loop over to display individual facet lists.
Read the facet value order
You need to list the attribute you want to display facets of insearchParameters.facets.
Read the possible results from result.facets[facetName].
After fetching those values, you can read the result.renderingContent.facetOrdering.values[facetName] object to sort them.
This object has the following keys:
order: an array of facet values to pin at the start of the listhide: an array of facet values to hide from the listsortRemainingBy: a string that describes how to sort the remaining values. Either “alpha” (alphabetically, ascending), “count” (value retrieved fromfacets[facetName][facetValue], descending), or “hidden”, which only displays the ordered items.