Dynamic Filtering
How does it work
When creating the project mapping (see the environment creation step), there is a parameter called categories
. This allows you to define how your products are categorized. Below is an example of how a skincare or cosmetics company might set up their categories. Note that all category keys must exist in your catalog.
"categories": [
{
"name": "product_categories",
"separator": ","
},
{
"name": "skin_types",
"separator": ","
},
{
"name": "product_brands",
"separator": ""
},
{
"name": "good_for",
"separator": ","
},
{
"name": "product_tags",
"separator": ","
},
{
"name": "key_ingredients",
"separator": ","
}
]
Once you've defined categories in the mapper, you can use them to generate filters dynamically in your search results.
Continuing from the previous example, suppose you hit the POST /v1/items/search
endpoint with the following request body. Notice the dynamic_filtering
parameter, where two values defined in the mapper is passed:
{
"user_id": "user12345",
"message": "lotion",
"type": "individual",
"price_lower": 1,
"price_upper": 10000,
"categories": [ ],
"flags": {},
"sort": {},
"dynamic_filtering": [
"product_categories",
"skin_types"
],
"details": false,
"start": 0,
"size": 3
}
In the response, along with the product list, you will see values under keywords
that can be used to generate dynamic filters:
{
"detail": {
"response": [
{
"title": "example product 1"
},
{
"title": "example product 2"
}
]
},
"summary": {
"keywords": {
"product_categories": [
"Skin Care",
"Toner/Lotion",
"International Brands"
],
"skin_types": [
"sensitive",
"dry",
"normal"
]
},
"max_price": 1980,
"min_price": 1350,
"total_hits": 102
}
}