We do not generally recommend "search on x characters" as it may lead to a confusing UX-- we may recommend trying to debounce sources as an alternative solution.
For 3.8 and upward:
You will need to override the functionality in view/frontend/web/autocomplete.js. Please note that you must override the functionality using Magento best practices. Where getItems takes the query, you can check the query length and return an empty array or return the sources as needed.
This is deprecated as of 3.8
For autocomplete, you can edit the "minLength" option. You will need to use this hook: beforeAutocompleteOptions. If for example you want this to run when three characters are entered, you would write options.minLength=3
. The full example snippet might look something like
algolia.registerHook('beforeAutocompleteOptions', function(options) {
options.minLength=3
return options;
});
For instantSearch you'd want to call the beforeInstantSearchInit hook and change the searchFunction For example, if we used the snippet noted here for changing search option, this may look like
algolia.registerHook('beforeInstantsearchInit', function(instantsearchOptions, algoliaBundle) {
instantsearchOptions.searchFunction = function(helper) {
if (helper.state.query.length > 3) {
helper.search();
}
}
return instantsearchOptions;
});
These snippets can go anywhere after the hooks are defined, and may vary according to your implementation.
Last reviewed 29-04-22.
Comments
0 comments
Article is closed for comments.