Exclude products from Autocomplete and Search result page

Hi there,

I am new to Algolia (but worked with a competitor for many years).

I have to deal with legacy products in a Magento store. The legacy products shall not be shown in the Autocomplete and also not in the search result page, as we only want to see the current products there. However, in the category /legacy, where the product list and filters are also handled by Algolia, I want to see all the legacy products (because there are only lecacy products there). I used to work with a competitor of Algolia for many years and I would use a ranking rule to downgrade all articles that are in the category path of /legacy. In the category /legacy those would also be downgraded, but as all of the are downgraded I would have the complete list. How would that be done with Algolia? It would be good to use the category path but it could also be a custom attribute like “legacy: yes/no” or a popularity attribute with all other products having 100 and the legacy products having 1 as value.

Thanks for any tip.

Cheers
Jörg

Hi Jörg!

In Algolia, this kind of use cases is typically handled with filters.

In your case, a simple solution could indeed to have an attribute legacy which takes a boolean. Then, in your front-end, you would always filter so that records with legacy: true are never returned, except when you are on page http://yoursite.com/legacy.

When using our Magento 2 integration, you also have access to an autocomplete menu (powered by our autocomplete.js library) and a results page (powered by our InstantSearch.js library). For both, we provide front-end events that you can hook into to tune the query before it’s dispatched to Algolia.

For the autocomplete, you could use the beforeAutocompleteSources hook to add an exclusive filter (with the NOT operator). You can find an example here.

For the search results page, you can use the beforeInstantsearchInit hook to do the same thing. You can find an example here.

Since you only want to apply the filter when the user isn’t on the /legacy page, you could leverage the URL Web API to decide whether or not to add the filter.

Best,

Thanks for the fast response, Sarah. We will try this, I’ll give feedback here.

Cheers,
Jörg