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 suggestions
To set up multi-index search experience so users can select a suggestion and use it to search the main index:1
Set up custom autocomplete component
Set up a custom autocomplete component with the
Vue Autosuggest library.
2
Wrap the conponent in the connector
Wrap the autocomplete component with the
ais-autocomplete connector.
For more infomation, see Autocomplete.Vue
3
Create the multi-index search experience
The
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.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