【问题标题】:How to sort IntPont or LongPoint field in Lucene 6如何在 Lucene 6 中对 IntPont 或 LongPoint 字段进行排序
【发布时间】:2016-07-13 17:23:56
【问题描述】:

嗨:我正在从 Lucene 5.1 迁移到 Lucene 6。我发现 InPoint 不支持排序,因为它的 DocValuesType 被冻结为 NONE 并且排序需要 NUMERIC。在 Lucene 5.1 中,我可以设置新字段的字段类型,这样我就可以进行基于范围的搜索并对结果进行排序。我知道我可以迁移到 LegacyIntField,但我想迁移到新的 IntPoint。有谁知道如何索引数值以支持基于范围的查询和排序?

谢谢!

【问题讨论】:

    标签: lucene


    【解决方案1】:

    您需要将值存储在 NumericDocValuesField 或其子类中。 doc.add(new NumericDocValuesField(field, 10));

    然后按此字段排名的搜索文档将是:

    Sort sort = new Sort(new SortedNumericSortField(field, SortField.Type.INT, true)); TopDocs topDocs = indexsearcher.search(query, returnedDocNum, sort);

    【讨论】:

    • 你不必使用 SortedNumericSortField,SortField 支持 doc values
    【解决方案2】:

    你必须使用额外的SortedNumericDocValuesField

    document.add(new SortedNumericDocValuesField("bid_sorter", bid));
    

    并根据它进行排序

    searcher.search(query, hitsPerPage, new Sort(new SortField("bid_sorter", SortField.Type.SCORE, true)))
    

    【讨论】:

    • 老实说 NumericDocValues 和 SortField 就足够了
    猜你喜欢
    • 2017-07-05
    • 1970-01-01
    • 2021-02-19
    • 2010-10-04
    • 2014-03-24
    • 1970-01-01
    • 1970-01-01
    • 2017-06-10
    • 2013-06-14
    相关资源
    最近更新 更多