对 multiValued 字段进行排序是否有任何解决方法? [英] Is there any workaround for sorting on multiValued field?

查看:22
本文介绍了对 multiValued 字段进行排序是否有任何解决方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以对文档的分数"或任何 multiValued="false" indexed="true" 字段进行排序,前提是该字段是非标记化的(即:没有分析器)或使用的分析器只产生一个 Term(即:使用 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)

文档:- http://wiki.apache.org/solr/CommonQueryParameters#sort

我原来的模式是(你可以认为下面是一个GROUP-BY):-

My original schema is (You can consider the following is a GROUP-BY) :-

  • 产品(id,唯一)
    • 发表评论的用户(multiValued)
    • 每个用户的last_comment_date(multiValued,一个用户可以进行多条评论,但只捕获最后一条评论的日期)

    如果允许对 multiValued 进行排序,
    我可以轻松获取某些用户评论的产品列表,
    然后按 last_activity_date 排序.

    If sorting on multiValued is allowed,
    I can easily get list of the products commented by certain users,
    then sort by last_activity_date.

    然而,它不起作用.
    我目前的解决方法是将架构反转为:-

    However, it does not work.
    The workaround I have currently is to reverse the schema to :-

    • 用户 + 产品(作为 ID,唯一)
    • 用户(单值)
    • last_comment_date
    • 产品

    这意味着我(某种程度上)设法获得了某些用户评论的产品列表,
    按 last_comment_date 排序,
    当然会导致产品重复
    因为产品会出现在每个用户的评论中.

    Which mean I (sort of) manage to get list of the products commented by certain users,
    order by last_comment_date,
    of course it lead to duplication of products
    as product will appear in each of the user's comment.

    任何模拟分组效果的建议.

    Any suggestion to simulate a group-by effect.

    在此之间,我使用的是 solr 3.1.
    字段折叠不适用.

    Between, I using solr 3.1.
    Field collapsing does not apply.

    推荐答案

    按多值字段排序不是等待执行或可以修补的事情.

    Sorting by a multi-valued field is not something that is just pending to do or can be patched.

    这是不可能的,因为它根本没有任何意义.

    It can't be possibly done because it simply doesn't make any sense.

    这样做的方法是为每个文档设置一个单值字段(在索引时间填充最后一个日期),然后对其进行排序.IE.索引时遍历具有上次活动日期的用户列表,找到最新日期,并将其分配给文档的上次活动日期字段.

    The way to do this is to have a single-valued field (populated at index-time with the last date) per document, then sort on that. I.e. when indexing traverse the list of users with their last activity date, find the latest date, and assign it to the document's last-activity-date field.

    这篇关于对 multiValued 字段进行排序是否有任何解决方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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