在Solr中,我可以对多值字段中的匹配值进行排序吗? [英] In Solr, can I sort on the matching value from a multi-valued field?

查看:185
本文介绍了在Solr中,我可以对多值字段中的匹配值进行排序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在考虑具有两个多值字段的架构.搜索是在第一个字段上执行的,但是应该使用相应的值在第二个字段上进行排序.例如.如果文档因第一个字段中的第n个值而匹配(每个匹配项中n可能不同),则应按第二个字段中的第n个值对它们进行排序.

We are considering a schema with two multi-valued fields. Search is performed on the first field, but sorting should be done on the second field, using the corresponding value. E.g. if documents match because of the n-th value in the first field (where n may be different for each match), then they should be returned sorted by the n-th value in the second field.

有可能吗?

背景:每个文档都有一个相似文档(ID)列表和一个相似度评分列表(值介于0和1之间).给定ID 42,我们需要返回所有相似的文档(例如,第一个字段中带有42的文档),并按与文档42的相似性进行排序.

Background: each document has a list of similar documents (IDs) and a corresponding list of similarity scores (value between 0 and 1). Given ID 42, we need to return all similar documents (e.g. documents with 42 in the first field), sorted by their similarity to document 42.

我们正在考虑的其他模式是:

Other schemas we are considering are:

  1. 每个ID的动态字段,因此当我们搜索类似于42的文档时,我们可以按字段Sameity_ID42进行排序.这似乎无法扩展,在800K +文档中,索引编制过程中CPU占用了100%的资源.
  2. 一个单一的多值字段,将"ID.score"存储为十进制(例如42.563),然后搜索值> 42 AND<的所有文档. 43,然后按该值排序(我什至不确定这样做是否可行).

推荐答案

该方法不会成功,因为您可以搜索,但不能按多值字段排序.这在在Solr中使用多值字段进行排序

The approach will not succeed, as you can search, but you cannot sort by a multivalued field. This pointed out in Sorting with Multivalued Field in Solr and written in Solr's Wiki

排序可以在文档的分数"上进行,也可以在任何multiValued ="false" indexed ="true"字段上进行,前提是该字段未进行令牌化(即:没有分析器)或使用的分析器仅产生一个字词(即:使用KeywordTokenizer)

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)

更新

关于替代方案,正如您指出的那样,您需要为一个给定的ID查找相似的文档,为什么不创建具有类似模式的第二个核心

About the alternatives, as you point out that you need to find similar documents for one given ID, why not create a second core with a schema like

<fields>
    <field name="doc_id" type="int" indexed="true" stored="true" />
    <field name="similar_to_id" type="int" indexed="true" stored="true" />
    <field name="similarity" type="string" indexed="true" stored="true" />
</fields>

<types>
    <fieldType name="int" class="solr.TrieIntField"/>
    <fieldType name="string" class="solr.StrField" />
</types>

然后,您可以在执行实际搜索之后再次查询

Then you could do a second query, after performing the actual search

q = similar_to_id = 42& sort =相似度

q=similar_to_id=42&sort=similarity

这篇关于在Solr中,我可以对多值字段中的匹配值进行排序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆