ais-search-box
. Once you’ve configured the generation of the Query Suggestions index, you need to query this index as well. Use multi-index search to do that.
This guide shows how to use a search box to display a list of suggestions and their associated categories.
Once users select a suggestion, Algolia will apply the query and the category.
If you’re building an autocomplete with Query Suggestions,
you should use the Autocomplete library which lets you build a full-featured,
accessible autocomplete experience.
This is the recommended way of building an autocomplete search with Algolia.
For more information, see:
- What is Autocomplete?
- Integrate Autocomplete with Vue InstantSearch
- Using Autocomplete with Vue
- Build a Query Suggestions UI with Autocomplete
Working example
This code has been specifically created for Vue 2.
Some modifications may be required for it to work correctly in Vue 3.
Refine your results with the suggestions
The first step is to set up a custom autocomplete component with the Vue Autosuggest library. You must then wrap the component with theais-autocomplete
connector. You can find more information in the guide on autocomplete.
Vue
ais-autocomplete
widget reads from two indices: instant_search_demo_query_suggestions
and instant_search
. The first index widget is implied by the creation of the ais-instant-search
widget. You can find more information in the autocomplete guide.
Vue
Use the related categories in the autocomplete
A typical use of autocomplete is to display both relevant categories and suggestions. Then when a user selects a suggestion, both the suggestion and the associated category are used to refine the search. For this example, the relevant categories are stored on the suggestions records. You must update your render function to display the categories with the suggestions. For simplicity and brevity of the code, assume that all suggestions have categories, but this isn’t the case in the actual dataset. Take a look at the complete example to see the actual implementation.Vue
ais-configure
widget with disjunctiveFacets
and disjunctiveFacetsRefinement
.
These two parameters are the same as internally used in a refinement list.
Vue