In Shopify, the default setting for facetingAfterDistinct is set to true. By default, Algolia computes facet counts before deduplicating records (distinct). When facetingAfterDistinct is set to true, Algolia calculates facet counts after deduplicating, this means that only the records being shown after deduplication are being counted towards facet hit counts, which can lead to lower hit counts than expected.
Changing this setting requires the use of custom hooks, specifically the beforeISStartAddWidgetArray to access the configure widget. Using this widget, we can change the value of facetingAfterDistinct to false.
For more information on how to get started with custom hooks, please see the following article.
The code that is required to make the change can be found below:
document.addEventListener("algolia.hooks.initialize", function () { algoliaShopify.hooks.registerHook("beforeISStartAddWidgetArray", function () { const { configure } = window.algoliaShopify.externals.widgets; configureWidget = configure({ facetingAfterDistinct: false, }); return [configureWidget]; }); });