We do not generally recommend "search on x characters" as it may lead to a confusing UX. We would recommend trying to debounce sources as an alternative solution.
For Algolia extension version 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.
For Algolia extension version 3.7 and below:
(This solution is deprecated as of 3.8 and we recommend upgrading to the latest version.)
For AutoComplete, you can edit the "minLength" option. You will need to use the hook beforeAutocompleteOptions.
If for example you want search 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 If we use the snippet noted here for changing search option, this might 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.