Sorting on multivalued field in Solr

2019-08-08 06:49发布

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?

3条回答
叼着烟拽天下
2楼-- · 2019-08-08 07:06

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.

查看更多
淡お忘
4楼-- · 2019-08-08 07:30

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

查看更多
登录 后发表回答