Configure Algolia

Edit on GitHub

Once you have integrated the Algolia app, you can configure it.

Prerequisites

To start using Algolia for your shop, you need an account with Algolia. You can create the account on the Algolia website.

Configure Algolia

To configure Algolia, do the following:

  1. In your store’s Back Office, go to Apps.
  2. In App Composition Platform Catalog, click Algolia. This takes you to the Algolia app details page.
  3. In the top right corner of the Algolia app details page, click Connect app. The notification saying that the application connection is pending is displayed.
  4. Log in to the Algolia website.
  5. On the Algolia website, go to Settings.
  6. Under Team and Access, click API keys.

algolia-keys

  1. From the Your API Keys tab, copy the following keys:
    • Application ID
    • Search-Only API Key
    • Admin API Key
  2. Go back to your store’s Back Office, to the Algolia app details page.
  3. In the top right corner of the Algolia app details page, click Configure.
  4. In the Configure pane, fill in the APPLICATION ID, SEARCH-ONLY API KEY, and ADMIN API KEY fields with the values from step 7.

algolia-settings

  1. Click Save.

The Algolia app is now added to your store and starts exporting your product data automatically.

Info

You need to wait for a few minutes until Algolia finishes the product export. The more products you have, the longer you have to wait. The average export speed is around 100 products per minute.

Verification

Verify that your index is populated with data from your store:

  1. Go to the Algolia website.
  2. In the side pane, go to Search > Index.
  3. Make sure that the index is populated with data from your store.

algolia-index-data

For details about the created index data, see Indexes.

Optional: Adjust Algolia configuration

The default Algolia app configuration mimics the default Spryker search configuration. However, you may want to adjust some of those settings to your needs.

Overview of searchable attributes

algolia-searchable-attributes

Algolia’s Searchable attributes configuration determines which attributes are used to find results while searching with a search query.

Default fields for searchable attributes are the following:

  • sku
  • name
  • description
  • keywords

Adjust the searchable attributes list in Algolia

  1. In the side pane, go to Search > Index.
  2. Open the Algolia indices list and find all primary indices.
  3. On the Configuration tab, select Searchable attributes.
  4. To adjust the Searchable attributes list, add and remove needed searchable attributes.
  5. Click Review and save settings. This opens the Review and save settings window.
  6. Enable Copy these settings to other indices and/or replicas and click Save settings.

Send additional fields to Algolia

Spryker’s Algolia PBC integration allows adding additional data to exported products. This is achieved using the pre-configured searchMetadata field on ProductConcrete and ProductAbstract transfers.

Filling in the searchMetadata field

There’re multiple ways of adding search metadata. For the sake of an example, we’ll implement ProductConcreteExpanderPlugin.

Create a new plugin implementing ProductConcreteExpanderPluginInterface. Then you can add any logic inside that plugin’s expand method to add necessary metadata to ProductConcrete transfers:


use Spryker\Zed\Kernel\Communication\AbstractPlugin;  
use Spryker\Zed\ProductExtension\Dependency\Plugin\ProductConcreteExpanderPluginInterface;

class SearchMetadataExampleProductConcreteExpanderPlugin extends AbstractPlugin implements ProductConcreteExpanderPluginInterface  
{  
    /**  
     * @param array<\Generated\Shared\Transfer\ProductConcreteTransfer> $productConcreteTransfers  
     *  
     * @return array<\Generated\Shared\Transfer\ProductConcreteTransfer>  
     */  
    public function expand(array $productConcreteTransfers): array  
    {  
        foreach ($productConcreteTransfers as $productConcreteTransfer)
        {
            $productConcreteTransfer->addSearchMetadata('isBestseller', true);
            // ...
            // OR
            // ...
            $searchMetadata = [
                'isBestseller' => true,
                'popularity' => 100,
            ];

            $productConcreteTransfer->setSearchMetadata($searchMetadata);
        }

        return $productConcreteTransfers;
    }  
}
Associative array

The searchMetadata field must be an associative array. Allowed values are all scalars and arrays.

Using searchMetadata field in Algolia

Algolia product object searchMetadata field is a simple object that can be used in any index configuration just like any other field.

Overview of facets list

algolia-facets

Algolia Facets configuration determines which attributes are used for search faceting.

Default attributes for faceting are as follows:

  • attributes.brand
  • attributes.color
  • category
  • label
  • prices
  • rating

The prices attribute is an object with nested fields. Algolia creates facets for each nested field and creates facets for all the currencies and pricing modes available in product entities.

Facet configuration

Searchable

Attributes defined as searchable may be used while calling Algolia’s searchForFacetValues method, which can be used for the Storefront integration. This method is necessary to display catalog page facets if many values are possible for each facet—in this case, only 100 of those values are displayed by default. Accessing other values requires searching for them using the searchForFacetValues method. Select this option if you plan on having a large number of different values for this facet, and if you use the Spryker Storefront.

Filter only

Attributes defined as filters only are not used for aggregation and can only be used to narrow down search result lists. This approach can be used with attributes for which aggregated counts are not important.

Glue API search response

Setting an attribute as filter only prevents it from showing in the facets list in the Glue API search response.

Not searchable

Default option. This facet configuration enables aggregation of search results by facet values. searchForFacetValues method can’t be used with facets configured this way. Use this option when you have limited facet values or plan on using something other than the Spryker Storefront.

After distinct checkbox

This checkbox is checked by default. Clearing this checkbox changes the calculation method for facet aggregation for the given field. By default, facet aggregation is calculated after search results for a given query are processed by deduplication or grouping process. It is not recommended to turn this checkbox off.

Algolia and Glue API facets interaction

When used with Algolia PBC, Spryker facets configuration is ignored and Algolia facets configuration is used instead. This means that Glue API response fields "valueFacets" and "rangeFacets" include facets configured in Algolia. Be wary that setting any Algolia facet to "filter only" mode removes it from the corresponding field in Glue API response.

Add new attributes for faceting

  1. In the side pane, go to Search > Index.
  2. Find all primary indices.
  3. On the Configuration tab, select Facets.
  4. To adjust the Attributes for faceting list, add and remove attributes.
  5. Click Review and save settings. This opens the Review and save settings window.
  6. Enable Copy these settings to other indices and/or replicas and click Save Settings.

Custom ranking and sorting

algolia-ranking

Algolia’s Ranking and sorting configuration determines which products can be shown before others when customers search your catalog. Spryker creates a Popularity index where you can use Product properties as ranking or sorting attributes. Learn more about Custom Ranking and Sorting in the Algolia documentation.