简体   繁体   English

在Solr中对多值字段进行排序

[英]Sorting on multivalued field in Solr

I know multivalued field sorting is not supported in Solr . 我知道Solr不支持多值字段排序。 But Is there any way we can sort multivalued field in Solr. 但是我们有什么方法可以在Solr中对多值字段进行排序。 I have two documents with field custom_code and values are as below, 我有两个带字段custom_code的文档,值如下,

Doc 1 : 11, 78, 45, 22 Doc 1:11,78,45,22

Doc 2 : 56, 74, 62, 10 Doc 2:56,74,62,10

When I sort it in ascending order the order should be , 当我按升序排序时,顺序应该是,

Doc 2 : 56, 74, 62, 10 Doc 2:56,74,62,10

Doc 1 : 11, 78, 45, 22 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). 这里Doc 2将首先出现,因为它具有最小的元素10(比文档1中的11个更大)。

How can we achieve this in Solr. 我们怎样才能在Solr中实现这一目标。 What is the easiest way? 什么是最简单的方法?

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. 因此,您可以做的另一件事是索引另一个字段min_code ,非多值并将custom_code的最小值放在那里。 You can do that in the client side or in Solr in a UpdateRequestProcessor. 您可以在客户端或在UpdateRequestProcessor中的Solr中执行此操作。 Then you just sort on min_code 然后你只需对min_code排序

Create a copyfield to copy the content of multivalued data into a sorted concatenated single value without commas and use it for sorting. 创建一个copyfield,将多值数据的内容复制到一个没有逗号的已排序的连续单个值中,并将其用于排序。

For Ex : 对于Ex:

Doc 1 : 文件1:

multiValuedData : 11, 78, 45, 22 multiValuedData:11,78,45,22

sortedConcatenatedSingleValue : 11224578 sortedConcatenatedSingleValue:11224578

Doc 2 : 文件2:

multiValuedData : 56, 74, 62, 10 multiValuedData:56,74,62,10

sortedConcatenatedSingleValue : 10566274 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. 如果在从源生成数据时无法创建此singlvalue字段,则可以在索引时使用脚本转换器( https://wiki.apache.org/solr/DataImportHandler#ScriptTransformer )来创建此sortedConcatenatedSingleValue字段一个javascript函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM