Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting with Multivalued Field in Solr

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?

like image 744
Ashutosh Avatar asked Oct 21 '11 05:10

Ashutosh


People also ask

What is multivalued field in SOLR?

A multivalued field is useful when there are more than one value present for the field. An easy example would be tags, there can be multiple tags that need to be indexed. so if we have tags field as multivalued then solr response will return a list instead of a string value.

What are multivalued fields?

A multivalued field (MVF) allows for the storage of more than one value in a database field. MVFs are somewhat controversial, with many arguing that they violate one of the very sacred tenets of database design as laid out by E.F.


1 Answers

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.

like image 120
Jayendra Avatar answered Sep 27 '22 16:09

Jayendra