Sorting with Multivalued Field in Solr

寵の児 提交于 2019-12-10 12:51:49

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/7845337/sorting-with-multivalued-field-in-solr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!