- Desktop
- Mobile

Understand the user interface
This example’s user interface consists of three search states, each one containing different plugins.Empty query state
The empty query state describes what users see in the search box before typing a search query. This example provides some recent and popular searches on the left (1 and 2) and quick access items on the right (3).
Recent searches
Theautocomplete-plugin-recent-searches
plugin fetches and then saves recent searches on the user’s local storage.
If there aren’t any recent searches,
the recent searches section is hidden.
A maximum of 4 recent searches are displayed by default.
To customize the plugin options,
edit the recentSearchesPlugin
file.
Popular searches
Theautocomplete-plugin-query-suggestions
plugin retrieves hits from the Query Suggestions index.
The first 6 most popular query suggestions
are displayed.
By default, query suggestions are sorted by the popularity
attribute in descending order (most popular first).
To customize the plugin options,
edit the popularPlugin
file.
Quick access
Quick access is a custom plugin that retrieves the JSON data from the response coming from a Rule configured in the Algolia dashboard on the products index. The rule is triggered by a rule context defined in the Autocomplete plugin. The example uses four item templates:sales-banner
, sales-code
, new-collection
, and help
.
template
value in the custom JSON data of the Rule and style it as you wish in the CSS file.
This is the rule’s custom JSON data structure:
JSON
quickAccessPlugin
file.
The complete rule configuration is in the products_configuration.json
file.
Results search state
The results search state appears as soon as you start typing a query in the search box. It provides multiple suggestions on the left and a preview of relevant products and articles on the right. The suggestions are combined using the Autocomplete Reshape API following two rules:- Suggestions are deduplicated between sources.
- A maximum of 1 category, 2 brands, and 1 FAQ are displayed. The rest is filled up with query suggestions to reach a total of 10 suggestions on desktop and 6 suggestions on mobile.

Key
- Product query suggestions
- Product category suggestions
- Product brand suggestions
- FAQ suggestions
- Products preview
- Articles preview
Product Query Suggestions
Theautocomplete-plugin-query-suggestions
plugin retrieves hits matching the query from the product Query Suggestions index.
A maximum of 10 product query suggestions are displayed by default.
To customize the plugin options,
edit the querySuggestionsPlugin
file.
Index records and configuration
Product category suggestions
Product category suggestions is a custom plugin that retrieves the category of the first matching product from the products index. A maximum of 1 product category is displayed by default. To customize the plugin, edit thecategoriesPlugin
file.
Product brand suggestions
Product brand suggestions is a custom plugin that retrieves the product brands facet values matching the query from the products index. A maximum of 2 product brands are displayed by default. To customize the plugin, edit thebrandsPlugin
file.
FAQ suggestions
FAQ suggestions is a custom plugin that retrieves an FAQ matching the query from the FAQ index. A maximum of 1 FAQ is displayed by default. To customize the plugin, edit thefaqPlugin
file.
The index records are in the faq.json
file.
Sample FAQ record
JSON
Products preview
Products preview is a custom plugin that retrieves products matching the query and displays a preview (including image, brand, name, price, and review rating/count) from the products index. A See All button that lists the number of other matching products (if any) is also displayed. A maximum of 4 product previews are displayed by default. To customize the plugin, edit theproductsPlugin
file.
Index records and configuration
Simplified sample record
JSON
Articles preview
Articles preview is a custom plugin that retrieves articles matching the query from the articles index. A See All button that lists the number of other matching articles (if any) is also displayed. A maximum of 2 article previews are displayed by default. To customize the plugin, edit thearticlesPlugin
file.
Index records
Sample record
JSON
No results search state
The no results search state is displayed when no results matching are found for the current query. It provides some advice on the left and popular categories on the right.
No results message
To customize the no results message, edit therender
method in the app.tsx
file.
Popular category suggestions
Popular category suggestions is a custom plugin that retrieves facet values for categories with the most number of products from the products index. Image URLs are hard-coded for the first 6 categories. To customize the plugin, edit thepopularCategoriesPlugin
file.
Technical requirements
Dependencies
The example has multiple dependencies:autocomplete-js
package with two plugins:autocomplete-plugin-query-suggestions
to add Query Suggestions.autocomplete-plugin-recent-searches
to display a list of the latest searches.
autocomplete-theme-classic
package as a neutral and clean theme starter.- Preact to render the virtual DOM.
- Ramda to pipe reshape functions.
- Parcel to bundle all the modules.
- BlurHash to have a placeholder for loading images.
- TypeScript for static type checking.
Structure
The folder structure of the example is as follows:src/components
: Preact componentssrc/functions
: Autocomplete reshape functionssrc/plugins
: Autocomplete custom pluginssrc/types
: Custom typessrc/utils
: Miscellaneous utilities
Combine different data sources
This example uses multiple Algolia indices hosted on Algolia’slatency
application.
If you intend to use your own Algolia indices or change the existing ones, the datasets and configurations are provided as JSON files in the Algolia datasets repository and described below.