Skip to content

Instantly share code, notes, and snippets.

@JanPetr
Created February 7, 2018 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JanPetr/c37f4b9731b268706b9068c0d361e2cc to your computer and use it in GitHub Desktop.
Save JanPetr/c37f4b9731b268706b9068c0d361e2cc to your computer and use it in GitHub Desktop.
Code to replace Magento extension's query suggestions by Algolia powered query suggestions Raw
function algoliaHookBeforeAutocompleteStart(sources, options, algoliaClient) {
for (var i = 0; i < sources.length; i++) {
if (sources[i].name === 'suggestions') {
var index = algoliaClient.initIndex('products_suggestions_query_suggestions'),
suggestionsSource = algoliaBundle.$.fn.autocomplete.sources.hits(index, {
hitsPerPage: 2 // FIX IT
});
sources[i] = {
source: suggestionsSource,
displayKey: 'query',
name: 'suggestions',
templates: {
suggestion: function (hit) {
hit.url = algoliaConfig.baseUrl + '/catalogsearch/result/?q=' + hit.query;
return algoliaConfig.autocomplete.templates.suggestions.render(hit);
}
}
};
break;
}
}
return [sources, options];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment