How to change indexName from the algoliabundle.min.js file in magento 2?

Hello,
I have installed algolia search extension on magento 2. I have to modify custom autocomplete result section on search bar.

When I type any query inside search box, I got the result from the Products, Category and Cms page indices on the autocomplete section.

Now I have to change logic for the CMS Pages with custom algolia indices. Need to change indices name for the magento2_default_pages with my custom indices name.

I have checked the code and autocomplete section result is coming from the algoliabundle.min.js file that contains the function callled,

Where the magento getting indices value from code level?
I have unminify algoliaBundle.min.js file and changed the logic,
(r.prototype.search = function (e, t, r) {
var i = n(18),
s = n(19),
a = “Usage: client.search(arrayOfQueries[, callback])”;
if (!i(e)) throw new Error(a);
“function” == typeof t ? ((r = t), (t = {})) : void 0 === t && (t = {});
var o = this,
c = {
requests: s(e, function (e) {
var t = “”;
return void 0 !== e.query &&
(t += “query=” + encodeURIComponent(e.query)), {
indexName: e.indexName, params: o._getSearchParams(e.params, t)
};
}),
},
u = s(c.requests, function (e, t) {
if (e.indexName.endsWith("_pages")) {
e.indexName = ‘dev_AEM_LANDSBERG’;
}
console.log(e.indexName);
return t + “=” + encodeURIComponent("/1/indexes/" +
encodeURIComponent(e.indexName) + “?” + e.params);
}).join("&"),
l = “/1/indexes//queries";
console.log(e);
console.log(‘request’, c.requests);
console.log(‘params’, u);
console.log(l);
return (
void 0 !== t.strategy && (c.strategy = t.strategy),
this._jsonRequest({ cache: this.cache, method: “POST”, url: l, body: c, hostType: “read”, fallback: { method: “GET”, url: "/1/indexes/
”, body: { params: u } }, callback: r })
);
}),", fallback: { method: “GET”, url: “/1/indexes/*”, body: { params: u } }, callback: r })
);
}),

How can e.indexName is coming in the above code?
Is there any setting to replace e.indexName with my custom indices name? Not sure how to change indexName from the PHP Code?

Hi there,

The index name is automatically generated by the Magento extension from your store ID, and passed as is to the JavaScript on window.algoliaConfig (as you can see here). The index name is accessible at window.algoliaConfig.indexName.

You can change this by mutating the value after it’s declared, but before the algoliaBundle script starts. One way of doing this is to override the template.

Does this help?

1 Like