Skip to main content

Using ranking

Abstract

Learn how to use the Search and Recommendation API for Sitecore Search to perform customized ranking.

You can add custom ranking to change the relevancy of an item in the search results. To perform customized ranking, use the widget.items.search.ranking object and specify a name and weight.

Note

Before you can use an attribute for ranking, make sure that you or an administrator mark the attribute as one that you want to use for ranking. You can do this in the Customer Engagement Console (CEC), under Administration, Domain Settings, attribute, Use For Features.

For the data model of this object, see the Search and Recommendation API reference.

For example, a visitor searches for product optimization and you have ten items in the results, each of which has a relevancy score. You can use customized ranking to increase or decrease the relevancy score of each item. If you rank by, say, descending order of review_rating, items with a greater review rating get a higher relevancy score.

The higher the weight, the more important Sitecore Search considers the attribute when it calculates the relevancy score. For example, if you want Sitecore Search to give more importance to the review_ratings attribute than to the color attribute, pass both attributes and assign review_ratings a higher weight.

Note

We recommend that you keep the weight to under five. This is to minimize the impact of a single attribute on the overall system.

In the following example, you want to assign the review_ratings attribute a weight of 1.15. The following code sample shows how to create a request:

{
    "widget": {
        "items": [
            {
                "rfk_id": "rfkid_7",
                "entity": "content",
                "sources": [
                    "388218",
                    "390565"
                ],
                "search": {
                    "content": {
                        "fields": [
                            "title"
                        ]
                    },
                    "ranking": [
                        {
                            "name": "review_rating",
                            "weight": 1.15
                        }
                    ]
                }
            }
        ]
    },
    "context": {
        "locale": {
            "country": "us",
            "language": "en"
        },
        "user": {
            "uuid": "159871551-1g-i4-4x-1p-f5tdhddqwvywv7b9g2vy-1664852644904"
        }
    }
}