
Before you begin
This tutorial requires InstantSearch.js.Implementation guide
In this guide, you build a classic ecommerce search page with a search box, guided search facets at the top, two facets (brand and price), and results.High-level approach
To create guided search facets, you need to create a UI for therefinementList
widget using connectors. Essentially, you override the out-of-the-box behavior of a refinement list widget with your own render function. You can find the code examples in the guide on the custom refinement list connector.
Before you get started, make sure you:
- Select an attribute as the guided facet filter and set it as one of the
attributesForFaceting
. - Set up your UI with the InstantSearch getting started guide.
- Declare attributes for faceting in the dashboard
- Declare attributes for faceting with the API
- Auto-selected facets
- Filter suggestions
- Visual facets
File and index structure
For this implementation, you need two files:index.html
main.js
instant_search_solutions_ecommerce
.
It’s a three-step process (this code is located in main.js
):
JavaScript
Create a render function
The rendering function is called before the query and each time results come back from Algolia. The function inmain.js
is populated with rendering options. This code creates the look and feel of the category’s facet values and defines the click-event behavior. It also manages the “show more” logic.
JavaScript
Create the custom refinementList
connector
JavaScript
Instantiate the custom refinementList
connector
Now add the new customized connector to your collection of widgets also in main.js
. You give it the container used by the HTML, as described in the next section. In the example, the container ID is #guided-search-facets
.
JavaScript
Update the HTML
The last step is to add the widget to yourindex.html
.
Here it’s positioned just under the search box.
HTML