// Creates a context variable with the category title (algoliaConfig.instant.title) // We have to format it for the variable to be usable in the Algolia dashboard (we replace everything which // is not a letter or a figure by a dash) // for example : "Pants & Denim" becomes "Pants-Denim" so the ruleContext is "category_Pants-Denim" function algoliaHookBeforeInstantsearchInit(instantsearchOptions) { var categoryContext = 'category_'+ algoliaConfig.instant.title.replace(/[^A-Za-z0-9_-]+/g, '-'); if (typeof instantsearchOptions.searchParameters.ruleContexts === 'undefined') { instantsearchOptions.searchParameters.ruleContexts = [categoryContext]; } else { instantsearchOptions.searchParameters.ruleContexts.push(categoryContext); } return instantsearchOptions; }
Comments
0 comments
Article is closed for comments.