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, enterALGOLIA_APP_ID and ALGOLIA_API_KEY obtained from the Algolia dashboard into the .env file.
Configuration
See the full settings reference here!
Important: The settings below are configured for the default Mercur storefront. If you’re using a custom storefront with different filtering requirements, you’ll need to adjust attributesForFaceting based on your specific filters. See the Custom Storefront Configuration section below.
Understanding attributesForFaceting
The AlgoliaattributesForFaceting setting is directly tied to the filters used in your storefront code.
The Rule:
- Every attribute you filter by in your storefront → Must be declared in
attributesForFaceting - Without this declaration, Algolia will ignore the filter or return 0 results
Default Storefront Configuration
The default Mercur storefront uses the following filters in product listing pages: Repository: mercurjs/b2c-marketplace-storefront Location:src/components/sections/ProductListing/AlgoliaProductsListing.tsx
variants.condition- Product condition (e.g., new, used, refurbished)variants.color- Product color optionsvariants.size- Product size options
Recommended Algolia Settings for Default Storefront
Important: Use the official configuration file from the storefront repository to ensure compatibility: 👉 View and download algolia-config.json This configuration includes all necessary settings for:attributesForFaceting- Required for filtering by category, seller, country, currency, etc.searchableAttributes- Product fields that are searchable- Ranking and relevance settings
- Facet ordering (color, size, condition)
-
Via Algolia Dashboard (recommended):
- Download the algolia-config.json file
- In Algolia Dashboard, go to your product index
- Select “Import configuration” from the “Manage index” dropdown
- Upload the downloaded file
-
Via API:
- Use the Algolia API to update index settings programmatically
- See Algolia setSettings documentation
-
attributesForFaceting - Enables filtering by:
categories.id- Filter products by categoryseller.handle- Filter products by vendor/sellerseller.store_status- Filter out suspended sellersseller.id- Filter by specific seller IDsupported_countries- Geographic filteringvariants.prices.currency_code- Currency-specific filteringvariants.color,variants.size,variants.condition- Product attributesattribute_values.nameandattribute_values.value- Custom attributes
- searchableAttributes - Defines which fields are searchable in text queries
- facetOrdering - Controls the order and display of facets in the storefront
filterOnly(attr)- Attribute can only be used for filtering (more memory efficient)searchable(attr)- Attribute can be used for both filtering and text search
Custom Storefront Configuration
If you’re building a custom storefront or modifying the default one, follow these steps:1. Identify Your Filters
Search your storefront code for Algolia filter usage. Common locations:- Product listing components
- Search components
- Category/collection pages
2. Map Filters to attributesForFaceting
For each attribute used in filters, add it toattributesForFaceting:
3. Choose the Right Prefix
- Use
filterOnly()for attributes that only need filtering (most common, more efficient) - Use
searchable()for attributes that should also be searchable via text query
4. Update and Test
- Update your Algolia index settings via dashboard or API
- Re-sync your products if needed
- Test filtering in your storefront to ensure it works
Product Visibility Requirements
For a product to be visible on the default Mercur storefront via Algolia search, it must meet all of the following conditions:- Product Status: Must be
published - Seller Assignment: Product must have an assigned seller with status
ACTIVE(notSUSPENDED) - Geographic Availability: Product’s
supported_countriesmust include the target country code - Pricing: All variants must have prices in the appropriate currency with
amount > 0 - Inventory: Variants must have properly configured inventory locations with fulfillment sets for the target country
Note: If you’re using a custom storefront, your visibility requirements may differ based on your filtering logic.
Events
In order to persist consistency between database and Algolia, every time any change in indexed entities happens an event is emitted, for example:algolia.products.changedalgolia.products.deleted
algolia.intermediate.fulfillment_set.changedalgolia.intermediate.service_zone.changedalgolia.intermediate.shipping_option.changedalgolia.intermediate.stock_location.changedalgolia.intermediate.inventory_item.changed
Troubleshooting
Products not showing on storefront
If your products are indexed in Algolia but not appearing on the storefront, verify:- Check attributesForFaceting - Ensure all attributes used in your storefront filters are declared in
attributesForFaceting - Verify filter values - Check that products have the values you’re filtering by (e.g.,
supported_countriescontains the target country) - Review pricing - Ensure all variants have prices in the correct currency (if you filter by currency)
- Confirm seller status - If filtering by seller status, verify it’s
ACTIVEand notSUSPENDED - Check product status - Ensure product status is
published - Inspect Algolia Dashboard - View your index in Algolia Dashboard to see actual data and test filters
Common Issues
Issue: “No results” on product listing page Most common cause: MissingattributesForFaceting configuration.
Solution:
- Check your storefront code to see what filters are applied
- Compare with your Algolia
attributesForFacetingsettings - Add any missing attributes to the Algolia configuration
- Re-sync products if needed
- Verify the attribute exists in your product data in Algolia
- Check that the attribute is declared in
attributesForFaceting - Use
filterOnly()prefix for filtering-only attributes - Use
searchable()prefix if you also need to search by this attribute
- New filters require corresponding
attributesForFacetingentries - Update Algolia index settings first
- Then add the filter to your storefront code
- Products without the filtered attribute value will be excluded (this is expected)