JavaScript
autocomplete widget to show suggestions.
When users select a suggestion, the widget navigates to the suggestion URL or refines the search query, depending on your configuration.
Open CodeSandbox
Run and edit the Query Suggestions UI example in CodeSandbox.
Explore source code
Browse the source code for the Query Suggestions UI example on GitHub.
This widget is and is subject to change in minor versions.
Add Query Suggestions and recent searches
The widget displays suggestions from a Query Suggestions index and recent searches stored in the browser’s local storage. Enable them withshowQuerySuggestions and showRecent:
JavaScript
Refine results with suggestions
To keep users on the same page, set up a multi-index search experience that uses the selected suggestion to search the main index. Theautocomplete widget targets the index that contains the suggestions.
The other widgets target the main index that contains your records.
For more information, see Multi-index search.
JavaScript
Customize recent searches
Pass an object toshowRecent to customize how each recent search renders:
JavaScript
Customize suggestions
Pass an object toshowQuerySuggestions to customize each suggestion and apply search parameters to the suggestions query:
JavaScript
ReverseHighlight to emphasize the text that doesn’t match the query.
This is a common style for Query Suggestions.
The widget has no built-in category grouping for suggestions and there’s no categoryAttribute.
To show a category next to a suggestion, render the category in the suggestion’s item template.
See also
- Autocomplete guide for the widget basics.