Getting similar items
You can use the widget.items.search.personalization object to get similar items to show visitors. You must add the fields that you want Sitecore Search to prioritize when looking for similar items and the document ids for which you want similar items.
For the data model of this object, see the Search and Recommendation API reference.
An example of using similar items is to show a Learn more button under each search result item. When the user clicks this button, they see a list of similar items.
Before you can get similar items, make sure that an administrator configures Personalization in Sitecore Search.
In the following example, you want to:
-
Get five items that are similar to the document ID https_www_sitecore_com_blog_ai-overcomes-bad-data. To do this, use the
idsarray within thewidget.items.search.personalizationobject and pass the ID ofhttps_www_sitecore_com_blog_ai-overcomes-bad-dataas the value. -
Ask Search to use the title and document type when it searches for similar content. To do this, use the
fieldsarray within thewidget.items.search.personalizationobject and passtitleandtypeas the values.
The following code sample shows how to create a request:
{
"widget": {
"items": [
{
"rfk_id": "rfkid_7",
"entity": "content",
"sources": [
"388218",
"390565"
],
"search": {
"content": {},
"personalization": {
"algorithm": "mlt",
"fields": [
"title",
"type"
],
"ids": [
"https___www_https_www_sitecore_com_blog_ai-overcomes-bad-data"
]
},
"limit": 5,
"offset": 0
}
}
]
},
"context": {
"locale": {
"country": "us",
"language": "en"
},
"user": {
"uuid": "159871551-1g-i4-4x-1p-f5tdhddqwvywv7b9g2vy-1664852644904"
}
}
}