Adding Categories to Query Suggestions
You can enhance query suggestions by adding categories or scope to your suggestions list.
Consider a Query Suggestions implementation that responds to the query “iphone”.
The standard approach is to present useful queries:
- “iphone 7”
- “iphone charger”
- “iphone X cases”
- “iphone X speakers”
With category suggestion, you can also present categories or scopes:
- in phones
- in accessories
- in electronics
Your suggestions list can contain a mix of pure query suggestions and category suggestions.
Adding category information to your suggestions index
Adding categories to your suggestions can be done through your dashboard.
- From the Query Suggestions tab of your dashboard, select the suggestions index you want to add categories to.
- Scroll down until you find the Categories heading.
- Click on the Edit categories button.
- In the input field, type in the name of your category attribute and select the number of top categories you want to display for it.
- To the right of the input field, click Add.
- Once you’ve added all your categories, click Save.
Once categories are set up, Algolia returns queries to your suggestions index with added category information. It will not automatically add the display logic for you. It’s up to you to choose:
- how to display the category-based suggestions,
- what to do when a category-based suggestions is clicked, selected, and hovered (we recommend redirecting to an InstantSearch page with a pre-filled query and adding a default filter for the chosen category).
To get a sense of what this looks like, check out our Query Suggestions demo.