0
votes

I have indexed "StockAvailability" field to Solr with true or false values. It means if products are in stock StockAvailability field has "True" value otherwise it has "False" value.

Now I want search result as per relevancy, means I want to show "In Stock" products first then "Out of Stock" products.

Example:

Assume if you search for "mouse", it returns 10 products. If product "mouse very special mouse" has no stock and remaining products have stock then I want to show all other products first which are in stock on search result page then out of stock products.

How can I perform a Solr as well as SolrNet query to do this?

Thanks.

1

1 Answers

0
votes

Based on what you have described, you need to sort your results. So applying a sort to the query on the StockAvailability field should get your desired results.

Solr:

http://<solrUrl>/select?q=mouse&sort=StockAvailability&20desc

SolrNet:

var results = solr.Query(new SolrQuery("mouse"), new QueryOptions {
    OrderBy = new[] {new SortOrder("StockAvailability", Order.DESC)}
});