【问题标题】:To add a list of Strings to Lucene document将字符串列表添加到 Lucene 文档
【发布时间】:2020-01-26 18:12:44
【问题描述】:

假设我有一个列表字段(例如:“Key”:[“value1”,“value2”,“value3”]。如何将它添加到序列映射中的 lucene 文档中。我是当前按顺序从文件中加载内容并将每个条目映射到文档,并为每个条目使用索引编写器添加文档。

seq(items)
        .map(item -> {
            Document document = new Document();
            document.add(new TextField("field", item.field(), Field.Store.YES));
            return document;
        })
        .forEach(consumer(indexWriter::addDocument));

我并不费力地将作为字符串列表的字段添加到上述索引文档中。有人可以帮忙吗?

【问题讨论】:

    标签: string list lucene


    【解决方案1】:

    您不需要为该字段中的每个值创建一个文档,但相反,使用相同的文档,您只需为列表的每个值使用 document.add(<field>)(前提是 field 定义为多值):

    Document document = new Document();
    seq(items).map(item -> {
      document.add(new TextField('field', item.field(), Field.Store.YES));
    });
    yourIndexWriter.addDocument(document);
    

    【讨论】:

    • 您好 EricLavault,感谢您的回复。问题更多是关于如何将作为字符串列表的字段添加到文档中。你能帮我吗?
    • 嗯..这正是上面的代码正在做的事情。它创建一个要索引的文档,然后对于给定字符串列表的每个值,将其添加到文档的 'field' (即具有多个值的单个字段),然后将文档发送到 solr。
    • 哦!我的错,对不起!感谢您的回复。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-09
    • 2011-09-10
    • 2018-08-12
    • 2014-07-05
    • 2021-06-09
    • 2021-06-27
    相关资源
    最近更新 更多