Algolia search engine
Introduction
Mercur uses Algolia as a search engine to boost product search accuracy and serving trending/recommended items. The integration features auto product indexing, whenever any of the product attributes was changed or a new product review is created.
Setup
In order to use Algolia, an account is needed. After registration, enter ALGOLIA_APP_ID
and ALGOLIA_API_KEY
obtained from the Algolia dashboard into the .env
file.
Then, run the sync-algolia
script, in order to apply the default settings, and synchronize already existing products/reviews.
Run the following command from the apps/backend
catalog:
Configuration
The default configuration is present in the apps/backend/src/modules/algolia/service.ts
file. You can adjust the defaultProductSettings
and defaultReviewSettings
to your needs. That includes the searchable fields, relevancy and ranking. See the full settings reference here. Default configuration includes only the searchable fields.
Events
In order to persist consistency between database and Algolia, every time any change in indexed entities happens an event is emitted, for example:
- Product is changed -
algolia.products.changed
- Product is deleted -
algolia.products.deleted
- Review is changed -
algolia.products.changed
Each event is connected to the subscriber, which is responsible for refetching the entity and updating it in Algolia.