Configure Algolia
Edit on GitHubOnce 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:
- In your store’s Back Office, go to Apps.
- In App Composition Platform Catalog, click Algolia. This takes you to the Algolia app details page.
- 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.
- Log in to the Algolia website.
- On the Algolia website, go to Settings.
- Under Team and Access, click API keys.
- From the Your API Keys tab, copy the following keys:
- Application ID
- Search-Only API Key
- Admin API Key
- Go back to your store’s Back Office, to the Algolia app details page.
- In the top right corner of the Algolia app details page, click Configure.
- In the Configure pane, fill in the APPLICATION ID, SEARCH-ONLY API KEY, and ADMIN API KEY fields with the values from step 7.
- Click Save.
The Algolia app is now added to your store and starts exporting your product data automatically.
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.
Verify that your index is populated with data from your store:
- Go to the Algolia website.
- In the side pane, go to Search > Index.
- Make sure that the index is populated with data from your store.
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’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
- In the side pane, go to Search > Index.
- Open the Algolia indices list and find all primary indices.
- On the Configuration tab, select Searchable attributes.
- To adjust the Searchable attributes list, add and remove needed searchable attributes.
- Click Review and save settings. This opens the Review and save settings window.
- 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;
}
}
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 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.
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
- In the side pane, go to Search > Index.
- Find all primary indices.
- On the Configuration tab, select Facets.
- To adjust the Attributes for faceting list, add and remove attributes.
- Click Review and save settings. This opens the Review and save settings window.
- Enable Copy these settings to other indices and/or replicas and click Save Settings.
Custom ranking and sorting
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.
Thank you!
For submitting the form