Sorting content results
The following examples show different types of sorting and continue from the querying product content example.
Sorting by name alphabetically
The following example shows you how to sort results by name in an ascending alphabetical order.
Here is the request:
RequestResponse
{
"query": {
"keyphrase": ["red"]
},
"n_item": 3,
"content": {},
"sort": {
"type": "name",
"order": "asc"
}
}Here is the response:
RequestResponse
{
"ts": 1480977544,
"rid": "response_id_150",
"url": "/searchpage?keyphrase=red&sort=na39dC",
"query2id": {
"keyphrase": "keyphrase_id_red"
},
"content": {
"product": {
"value": [
{"name": "jacket", "color": "red", "price": 80 },
{"name": "pants", "price": 50, "category_name": ["red"] },
{"name": "red dress", "price": 100}
]
}
},
"n_item": 3,
"total_item": 5,
"page_number": 1,
"total_page": 2
}Sorting by price from high to low
The following example shows you how to sort the results by price in a descending order..
Here is the request:
RequestResponse
{
"query": {
"keyphrase": ["red"]
},
"n_item": 3,
"content": {},
"sort": {
"type": "price",
"order": "desc"
}
}Here is the response:
RequestResponse
{
"ts": 1480977544,
"rid": "response_id_151",
"url": "/searchpage?keyphrase=red&sort=pas31pJ",
"query2id": {
"keyphrase": "keyphrase_id_red"
},
"content": {
"product": {
"value": [
{"name": "red dress", "price": 100},
{"name": "jacket", "color": "red", "price": 80 },
{"name": "pants", "price": 50, "category_name": ["red"] }
]
}
},
"n_item": 3,
"total_item": 5,
"page_number": 1,
"total_page": 2
}Sorting by both price and name
The following example shows you how to sort results using both sorting types, price and name. You first want to sort by price in an ascending order. If the price is the same, you next want to sort by name in an ascending order.
Here is the request:
RequestResponse
{
"query": {
"keyphrase": ["red"]
},
"n_item": 3,
"content": {},
"sort": {
"value": [{
"type": "price",
"order": "desc"
},
{
"type": "name",
"order": "asc"
}
]
}
}Here is the response:
RequestResponse
{
"ts": 1480977544,
"rid": "response_id_151",
"url": "/searchpage?keyphrase=red&sort=pas31psdpDa",
"query2id": {
"keyphrase": "keyphrase_id_red"
},
"content": {
"product": {
"value": [{
"name": "dress",
"price": 100,
"color": "red"
},
{
"name": "red dress",
"price": 100
},
{
"name": "jacket",
"color": "red",
"price": 80
}
]
}
},
"n_item": 3,
"total_item": 5,
"page_number": 1,
"total_page": 2
}