The sort request object
You can add a sort JSON object in a Sitecore Discover Search and Recommendation request. You use a value object to specify the order of the content search results. The value object contains a list of objects, and each object contains a sort type and order type.
You set up the default and available sort values in the Customer Engagement Console (CEC) when you first create an account with Discover.
The following code shows the structure of a sort object in a request:
{
"sort": {
"value": [{
"type": "<sort_type>",
"order": "<order_type>"
}
]
}
}Keys
The following table describes the key that the sort object contains.
|
Key |
Type/default value |
Description |
|---|---|---|
|
|
Optional. Determines the sort order of the content results based on the |
Sort object
The following table describes the keys in the sort object:
|
Key |
Type |
Description |
Value |
|---|---|---|---|
|
|
string |
Required. The sort types you want to sort by. |
|
|
|
string |
Required. Whether you want to sort in an ascending or descending order. |
|
Sort types
We typically support the following sort types:
|
Sort |
Description |
|---|---|
|
|
Sort by a mix of vendor rules, popular, individualized. |
|
|
Sort by name. |
|
|
Sort by price. |
|
|
Sort by recently added. |
|
|
Sort by product review rating. |
|
|
Sort by the number of reviews. |
See the CEC for the sort choices applicable to your account.
Example
You need a request to search for red products and then:
-
Sort by
pricefrom high to low (desc) -
If the
priceis the same, sort bynamealphabetically (asc)
This is a sample request:
{
"query": {
"keyphrase": ["red"]
},
"n_item": 3,
"content": {},
"sort": {
"value": [{
"type": "price",
"order": "desc"
},
{
"type": "name",
"order": "asc"
}
]
}
}For more examples, see Sorting content results.