Reputation: 89
In solr official document found the below info,
inStock desc, price asc Sorts by the contents of the inStock field in descending order, then within those results sorts in ascending order by the contents of the price field.
I am bit confused by reading this. If the document first sort by instock and we are getting the result and on that result if we again sort the same with price field then whatever the result we will get is not that same with the result - if first time only we will sort the result using price field. And if so then what is the benefit of doing sort by using instock field because finally we are getting the result sorted by price.
Somewhere i am understading it wrong i guess. Please help me to understand it.
Upvotes: 1
Views: 1082
Reputation: 2222
In Solr if we use sort on multi fields like inStock desc, price asc then first it will sort by inStock and after that it will sort by price only within those results in which inStock values are equal.
Like Below first we sort by inStock desc.
"response":{"numFound":3,"start":0,"docs":[
{
"inStock":5,
"price":10},
{
"inStock":4,
"price":2},
{
"inStock":4,
"price":1}]
}}
Then if we sort by inStock desc, price asc. Second sort is apply to only those results in which inStock values are equal.
"response":{"numFound":3,"start":0,"docs":[
{
"inStock":5,
"price":10},
{
"inStock":4,
"price":1},
{
"inStock":4,
"price":2}]
}}
Upvotes: 3