Sorting
In addition to search, we also need to provide sorting options on an e-commerce website. By default, the search results are ordered by the relevancy score that has been computed on the basis of the boosting we have provided. However, there would still be requirements to sort the search results by other factors such as price
, discount
, or latest products
. Sorting by already known fields is simple. All we need to do is add the sorting criteria behind our Solr search query:
sort=price asc
Alternatively, add the following sorting code:
sort=price desc
The intelligence that needs to be built into the system here is sorting by relevance after price
. This is to take care of scenarios where the ordered results may contain irrelevant results in the top when, say, sorted by price in the ascending order. Therefore, we would be modifying our query to include the score while sorting:
sort=price asc,score desc
Now, the top results would be better. Another intelligence that needs to be taken care of...