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.

Note

Before you can get similar items, make sure that an administrator configures Personalization in the Customer Engagement Console (CEC).

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 ids array within the widget.items.search.personalization object and pass the ID of https_www_sitecore_com_blog_ai-overcomes-bad-data as the value.

  • Ask Search to use the title and document type when it searches for similar content. To do this, use the fields array within the widget.items.search.personalization object and pass title and type as the values.

The following code sample shows how to create a request:

RequestResponse
{
    "widget": {
        "items": [
            {
                "rfk_id": "rfkid_7",
                "entity": "content",
                "sources": [
                    "388218",
                    "390565"
                ],
                "search": {
                    "content": {},
                    "personalization": {
                        "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"
        }
    }
}

Do you have some feedback for us?

If you have suggestions for improving this article,