Walkthrough: Adding the option to sort by top views

Sitecore Search tracks statistics such as clicks, conversions, views, and searches over time periods ranging from 1 day to 90 days. These statistics are stored as inner attributes within the rfk_stats composite attribute. Sitecore Search uses these attributes internally to generate analytic reports, but you can also use them on your site as sorting options.

By default, search results are displayed in descending order by relevancy score, but you can create other sorting options using the Customer Engagement Console (CEC). Using the inner attributes from rfk_stats, you can enable visitors to sort by content that is most clicked on, most viewed, and so on. In this walkthrough, you will learn how to add the option for visitors to sort by top views over the last seven days.

Note

Although this walkthrough covers the 7 Days Views attribute specifically, you can use the same process to enable sorting by any inner attribute from rfk_stats or any other composite attribute.

This walkthrough describes how to:

  • Enable the sorting option feature for the 7 Days Views attribute.

  • Add that attribute as a sorting option for your domain.

  • Turn on the sorting option in the global widget settings.

Enable the sorting option feature for the 7 Days Views attribute

To add an attribute as a new sorting option, you must first ensure the attribute is enabled with the sorting option feature.

To enable the sorting option feature for the 7 Days Views attribute:

  1. In the CEC, on the menu bar, click Administration > Domain Settings > Attributes.

  2. On the Attributes tab, in the search box, enter rfk_stats. Then click on it in the tabular list. This opens the attribute configuration page.

  3. On the left vertical menu bar, click Inner Attributes. This opens a list of inner attributes.

  4. In the list of inner attributes, click 7 Days Views. This opens the attribute editing dialog.

  5. In the attribute editing dialog, on the Use For Features tab, select the Sorting Options check box.

  6. Click Apply, then click Save.

Add the attribute as a sorting option

After making the 7 Days Views attribute available as a sorting option, you must add it to the sorting options list in order for it to be used on your domain.

To add 7 Days Views to the sorting options list:

  1. In the CEC, on the menu bar, click Administration > Domain Setting > Feature Configuration > Sorting Options.

  2. Scroll to the bottom of the list of sorting options, then click Add Sorting Option.

  3. Click Edit at the top of the new sorting option.

  4. In the DISPLAY NAME field, enter a short but descriptive name.

    For example, Top viewed this week.

  5. In the API NAME field, enter a name for the sorting option without escape characters and then click Save.

    For example, top_viewed_this_week.

  6. In the sorting type drop-down menu, click Attribute Sorting.

  7. In the Select Attribute drop-down menu, click 7 Days Views.

  8. In the sorting direction drop-down menu, click Ascending or Descending.

  9. Optionally, you can add additional tie-breakers by clicking Add Sorting Criteria on the sorting option card and repeating steps 6 through 8.

  10. Click Save, then click Publish. This opens a dialog box. Confirm your changes by clicking Publish again in the dialog box.

Turn on the sorting option in the global widget settings

If you do not turn on any sorting options in the global widget settings, the API returns all sorting options created in feature configuration. However, if any sorting options are turned on in the global widget settings, only the ones that are turned on are returned by the API.

Important

We recommend you turn on new sorting options in the global widget. However, if this is not the first sorting option and no other sorting options are turned on, do not complete this step because otherwise, all other sorting options are disabled.

Turning on sorting options in global widget settings allows you to have more control over which sorting options are returned by creating a default configuration that can be overridden at the individual widget level with rules. It also makes it possible to create many potential sorting options in feature configuration and then only turn on the ones you need.

To configure the sorting option in the global widget:

  1. In the CEC, on the menu bar, click Global Resources, then click Global Widget.

  2. On the Global Widget Settings tab, click the Sorting card.

  3. On the card for the new sorting option, turn on the switch.

  4. Optionally, if you want this sorting option to be the default, click Make Default.

  5. Click Save, then click Publish. This opens a dialog box. Confirm your changes by clicking Publish again in the dialog box.

Important

After completing this step, you must reindex your content for the new sorting option to be available for use.

Do you have some feedback for us?

If you have suggestions for improving this article,