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.

Note

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.

KeyType/default valueDescription
valueSort objectOptional.

Determines the sort order of the content results based on the <sort_type> and <order_type>.

Sort object

The following table describes the keys in the sort object:

KeyTypeDescriptionValue
typestringRequired.The sort types you want to sort by.featured (default)namepricenewestratingreview
orderstringRequired.Whether you want to sort in an ascending or descending order.asc (default)desc

Sort types

We typically support the following sort types:

SortDescription
featuredSort by a mix of vendor rules, popular, individualized.
nameSort by name.
priceSort by price.
newestSort by recently added.
ratingSort by product review rating.
reviewSort by the number of reviews.
Note

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 price from high to low (desc)
  • If the price is the same, sort by name alphabetically (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.

If you have suggestions for improving this article, let us know!