Skip to main content
The Algolia extension for Adobe Commerce and Magento Open Source uses the Autocomplete UI library to create the menu that appears below the search box. You can find all templates, JavaScript files and style sheets in the directory: vendor/algolia/algoliasearch-magento-2/view/frontend/web. As a starting point for your customizations, use the CustomAlgolia starter code.

Concepts

Frontend events let you run functions (hooks) at specific stages in the lifecycle of the autocomplete menu. You can use them to change the structure of your data, its sources, and the configuration options for your autocomplete menu. For more information, see Frontend custom events. Templates let you control the look of your autocomplete menu with JavaScript template literals.

Basic configuration options

To change the autocomplete options, use the afterAutocompleteOptions hook. For example:
JavaScript

Sources

Sources provide the data for items that your users can search for in the autocomplete menu. Specifying multiple sources lets you create a federated search experience. Autocomplete sources show matches from different indices or other data sources The Algolia extension comes with default sources. To change them, go to Stores > Configuration > Algolia Search > Autocomplete in your Magento Admin. You can select these sources:

Add new sources

To add new sources to the autocomplete menu or change existing ones, use the afterAutocompleteSources hook. The callback function for afterAutocompleteSources must return the complete sources array. For example:
JavaScript
The callback for afterAutocompleteSources accepts two parameters: If you need access to other objects, such as algoliaAnalytics, use RequireJS to define them as dependency for your algoliaHooks implementation.

Sources data structure

A minimal configuration for your source object might look like the following:
JavaScript
Each source in the sources array is a JavaScript object with the following properties:

Examples

The following example hook adds a new source:
JavaScript
The following example changes an existing source:
JavaScript

Plugins

Plugins extend Autocomplete---for example, by adding new sources. The Magento extension includes the Query Suggestions plugin. This plugin shows popular searches in your autocomplete menu as search suggestions. To add new plugins or change existing ones, use the afterAutocompletePlugins hook. For example, to add recent searches to your autocomplete menu:
JavaScript

Click events

When a user selects an item in the menu, Autocomplete sends a click event. To track custom events, see Custom frontend events.

Keyboard navigation

Keyboard navigation is available in the Algolia extension for Magento Open Source and Adobe Commerce version 3.9.2 or later.
To turn off keyboard navigation, go to Stores > Configuration > Algolia Search > Enable keyboard navigation in the Magento Admin. By default, keyboard navigation is turned on. Screenshot of two drop-down menu: 'Enable autocomplete menu's debug mode' and 'Enable keyboard navigation', both set to 'Yes'.
Autocomplete implements the WAI-ARIA combobox pattern.

Autocomplete menu templates

When updating templates, keep the changes in your theme directory. Avoid editing the theme files in the extension directory. Follow theme development best practices. To change the appearance of the autocomplete menu, override these templates in your theme: You can find all template files in the web/js/template/autocomplete/ directory.

JavaScript mixins with RequireJS

Mixins let you change the rendering of specific parts of a template without having to override the entire file. To do this, create a requirejs-config.js file in your theme or custom module:
JavaScript
The following mixin example adds the product’s SKU to each product in the autocomplete menu. It overrides the getItemHtml function, leaving other aspects unchanged.
JavaScript
To only change specific aspects, you can create mixins for methods such as getColorHtml or getCategoriesHtml without editing the getItemHtml function.

Customization with wrappers

You can also extend templates with Magento’s mage/utils/wrapper JavaScript module. Wrappers let you invoke the original template function and include its output with the _super method. The following example overrides the getHeaderHtml method of the Autocomplete category hit template:
Javascript
This renders the following results: Using wrappers in your mixins for invoking the original method and using its output For more information, see JavaScript mixins in the Adobe Commerce documentation.

Custom Algolia module

To help you build your mixins faster, try the Algolia_CustomAlgolia extension which installs a set of starter templates for your customizations. For more information, see Create a custom extension.

Styling

To keep the autocomplete menu open when making changes, turn on the debug mode. To enable the debug mode, go to Stores > Configuration > Algolia Search > Autocomplete > Enable autocomplete menu’s debug mode. Using wrappers in your mixins for invoking the original method and using its output

Debouncing

Debouncing waits to send a until the user stops typing for a short time. This reduces the number of API requests and UI updates but it also delays showing results. Debouncing can help users who prefer reduced motion. To change the debounce settings, go to Stores > Configuration > Algolia Search > Autocomplete in the Magento Admin.

Debounce requests

The Debounce requests setting defines the delay after the last keystroke before triggering a search. By default, a search is triggered 300 milliseconds after the last keystroke. Screenshot of the 'Debounce requests' setting set to 300 milliseconds for the Algolia Search API.

Minimum query length

The Minimum query length setting defines how many characters users have to enter before triggering a search. If you set it to 0, searches are triggered from the first keystroke. Screenshot of a settings form with 'Minimum query length' set to '0' for search queries.

Custom theme

By default, the extension overrides the topSearch block of the template. If you’re using a custom theme without the topSearch block, update the DOM selector for the search input. Go to Stores > Algolia Search > Autocomplete Menu in the Magento Admin, and change the Search Input Container Selector setting: Screenshot of settings with 'Enable Autocomplete Menu' set to 'Yes', 'Search Input Container Selector' as '.Algolia-search-input', and 'Number of products' set to '6'.

Console error after reindexing

If you see the “can’t read property ‘autocomplete’ of undefined” error after reindexing, this indicates the extension’s templates weren’t rendered.
  1. Since the templates are rendered into the before_body_end block, ensure the theme renders this block.
  2. If the block is rendered, confirm that symlinks are enabled in Magento’s configuration.
Enable this in the administration section by going to System > Configuration > Advanced > Developer.
Last modified on June 19, 2026