Sorting with Multivalued Field in Solr
Sorting on multivalued fields does not work fine with Solr.
Documentation
Sorting can be done on the "score" of the document, or on any multiValued="false" indexed="true" field provided that field is either non-tokenized (ie: has no Analyzer) or uses an Analyzer that only produces a single Term (ie: uses the KeywordTokenizer)
When you want to sort the products from low to high or high to low, what price will Solr pick ? As from the example you have a Sell price of 0 as well as 195 ?
The function queries also do not allow to use max or min on the multivalued fields.
The option you have to save the highest and lowest sell price as single valued fields, and use those fields for sorting.
highest_sell_price=195
lowest_sell_price=0
and use these fields for sorting.
Admin
Updated on June 08, 2022Comments
-
Admin almost 2 years
I Have a Solr index that stores Price in a multivalued field for each Product.
I need to sort the result set by Price where the Price is Low to high and High to Low.
I try to use sorting on Price it's showing Error You can't sort on multivalued=True fields.
below is my solr XML
<arr name="sellprice"> <float>195.0</float> <float>136.5</float> <float>10.0</float> </arr>
in schema.xml
<field name="sellprice" type="float" indexed="true" stored="true" multiValued="true"/>
In C# Code
ISolrQueryResults<ProductTest2> powerArticles = solr.Query(new SolrQuery("WebCategory_Id:10") && new SolrQueryInList("FilterID", 146), new QueryOptions { FilterQueries = new[] { new SolrQueryByRange<decimal>("sellprice", 10, 40) }, OrderBy = new[] { new SolrNet.SortOrder(sellprice, desc) } });
Can somebody explain with some good example?
-
Admin over 12 yearsif i pick low to high then min price and high to low then Max price.
-
Jayendra over 12 yearsUpdated the answer, there seems to be no direct way for doing this.
-
Admin over 12 yearsThanks for your Quick response. I have also posted a new Question please suggest me with an example. stackoverflow.com/questions/7846018/…
-
Jayendra over 12 yearsIf it answers your question, might help to accept the answer.