Using filtering, rules, and content types to create a complex request for recommendations
You can specify exactly what you want to show as recommendations by using the recommendations.content, recommendations.filter and recommendations.rule objects.
For the complete data model, see the Search and Recommendation API reference.
For example, you want to get recommendations in the following scenario:
-
You want only the title and image attribute values for each content item. To do this, pass
titleandimageas values of therecommendations.content.fieldsobject. -
You want to filter recommendations by geographical region. Specifically, you want recommendations relevant to a visitor who is at 37.8136 degrees South and 144.9631 degrees West. To do this, use the
recommendations.filterobject, specifygeoDistanceas the filter type and define a radius (thedistance) within which to look for recommendations. -
You want to boost items that have a type attribute value of news into the first slot. To do this, use the
recommendations.ruleobject, specifyboostas the rule type, and set theslotsto 1.
Here's a sample request:
{
"context": {
"locale": "en-us",
"page": {
"uri": "/sample-page"
},
"user": {
"uuid": "123e4567-e89b-12d3-a456-426614174000"
}
},
"source": "12345",
"widget": {
"items": [
{
"entity": "content",
"rfk_id": "rfkid_1",
"recommendations": {
"content": {
"fields": [
"title", "image"
]
},
"filter": {
"type": "geoDistance",
"name": "location",
"distance": "50km",
"lat": 37.8136,
"lon": -144.9631
},
"limit": 5,
"rule": {
"boost": [
{
"filter": {
"type": "eq",
"name": "type",
"value": "news"
},
"slots": [
1
],
"weight": 1
}
]
}
}
}
]
}
}