Sorting on multivalued field in Solr

你离开我真会死。 提交于 2019-12-24 15:33:40

问题


I know multivalued field sorting is not supported in Solr . But Is there any way we can sort multivalued field in Solr. I have two documents with field custom_code and values are as below,

Doc 1 : 11, 78, 45, 22

Doc 2 : 56, 74, 62, 10

When I sort it in ascending order the order should be ,

Doc 2 : 56, 74, 62, 10

Doc 1 : 11, 78, 45, 22

Here Doc 2 will come first because it has smallest element 10 (which is greater that 11 of doc 1).

How can we achieve this in Solr. What is the easiest way?


回答1:


Create a copyfield to copy the content of multivalued data into a sorted concatenated single value without commas and use it for sorting.

For Ex :

Doc 1 :

multiValuedData : 11, 78, 45, 22

sortedConcatenatedSingleValue : 11224578

Doc 2 :

multiValuedData : 56, 74, 62, 10

sortedConcatenatedSingleValue : 10566274

If you cannot create this singlvalue field at the time of generating the data from source then you can use a script transformer (https://wiki.apache.org/solr/DataImportHandler#ScriptTransformer) during the index time to create this sortedConcatenatedSingleValue field using a javascript function.




回答2:


if this issue was implemented you could just use that, as in the description of the ticket. But it is not as of yet.

So, one other thing you can do is to index an additional field min_code, non multivalued and put the minimum value of custom_code in there. You can do that in the client side or in Solr in a UpdateRequestProcessor. Then you just sort on min_code




回答3:


You can get out of box in 5.3 - https://issues.apache.org/jira/browse/SOLR-2522

A good description is here - https://lucidworks.com/blog/2015/09/10/minmax-on-multivalued-field/



来源:https://stackoverflow.com/questions/30183667/sorting-on-multivalued-field-in-solr

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