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
renderingContent
setting. 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
- 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
To replicate the preceding dashboard example, use the API client’ssetSettings
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:- InstantSearch.js version 4.72.0 or later (see Upgrade guide).
- Add refinement widgets for the different facets.
- Add a
dynamicWidgets
container around the widgets you want to sort. - In those widgets, remove any custom
sortBy
or setfacetOrdering
totrue
.
JavaScript
Optimize dynamic widget network requests
Algolia automatically mounts the appropriate widgets for the search results.- In versions 4.32 to 4.35, dynamic widgets request all facets and generate an extra network request for this.
To avoid this, set
facets
to[]
(empty). - In version 4.36 and later, to avoid an extra request,
facets
is set to[*]
by default. If you prefer to do two network requests with only the relevant facets returned, setfacets
to[]
.
JavaScript
Widget limitation
This applies to InstantSearch.js version 4.36 and later.
-
Add an
applicable_facets
facet 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
facets
to[]
(empty).JavaScript -
Ensure that
applicable_facets
is always requested. Such as from a hidden menu:JavaScript -
Use
transformItems
ofdynamicWidgets
to useapplicable_facets
for dynamic widget rendering:JavaScript
Build the UI without InstantSearch
If you aren’t using InstantSearch to build your UI, you need to build frontend logic to:- Interpret the
renderingContent
parameter returned along search results, - Order facets and values based on your interpretation of the
renderingContent
parameter 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.