Walkthrough: Adding an attribute as a sorting option
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). For example, you might create options for users to sort results by product name, price, or total sales.
This walkthrough describes how to:
-
Enable the sorting option feature for an attribute.
-
Add that attribute as a sorting option for your domain.
-
Turn on the sorting option in global widget settings.
Enable the sorting option feature for an attribute
In order for an attribute to be accessible for use in sorting, you must enable the sorting option feature.
Only attributes with the following data types can be added as sorting options: string, integer, float, and timestamp.
To enable sorting by an attribute:
-
In the CEC, on the menu bar, go to Administration > Domain Settings > Attributes.
-
To filter the list of attributes by entity, in the Entity drop-down, select the checkbox for the type of entity you want to show and click Apply.
-
To search for an attribute, in the search bar, enter the attribute name. Then, click on the attribute in the tabular list. This opens the attribute configuration page.
-
On the left vertical menu bar, on the Use for Features tab, select the Sorting Options check box.
-
Click Save.
Add an attribute as a sorting option
After making an 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 an attribute to the sorting options list:
-
In the CEC, on the menu bar, click Administration > Domain Setting > Feature Configuration.
-
Click Sorting Options and then click Add Sorting Option
.
-
Click edit
at the top of the new sorting option.
-
In the DISPLAY NAME field, enter a short but descriptive name.
-
In the API NAME field, enter a name for the sorting option without escape characters and then click Save.
-
In the sorting type drop-down menu, click Attribute Sorting.
-
In the Select Attribute drop-down menu, click the attribute you want to sort by.
-
In the sorting direction drop-down menu, click Ascending or Descending.
-
Optionally, you can add additional tie-breakers by clicking Add Sorting Criteria on the sorting option card and following steps 6 through 8.
-
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 global widget settings
Finally, we recommend that you turn on your new sorting option in the global widget settings. If you do not turn on any sorting options in global widget settings, all sorting options created in feature configuration are returned by the API. 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.
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.
Although we recommend you turn on sorting options in the global widget, if no existing sorting options are turned on, do not complete this step or all other sorting options will be disabled.
To configure a sorting option in the global widget:
-
In the CEC, on the menu bar, click Global Resources, then click Global Widget.
-
On the Global Widget Settings tab, click the Sorting card.
-
On the card for the new sorting option, turn on the switch.
-
Optionally, if you want this sorting option to be the default, click Make Default.
-
Click Save, then click Publish. This opens a dialog box. Confirm your changes by clicking Publish again in the dialog box.