[英]To add a list of Strings to Lucene document
Suppose I've a field which is a List (Say : "Key" : ["value1", "value2", "value3"]. How do add it to a lucene document in a sequence map. I'm currently loading the content from a file in a sequence and mapping each entry to a document and for each entry adding the document using index writer.假设我有一个列表字段(例如:“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));
I'm not struggling to add a field which is a list of strings to the above index document.我并不费力地向上述索引文档添加一个字符串列表字段。 Can someone please help ?
有人可以帮忙吗?
You don't need to create a document per value in that field but conversely, using the same document you just use document.add(<field>)
for each value of the list (provided that field is defined as multivalued) :您不需要为该字段中的每个值创建一个文档,相反,使用相同的文档,您只需将
document.add(<field>)
用于列表的每个值(前提是该字段定义为多值):
Document document = new Document();
seq(items).map(item -> {
document.add(new TextField('field', item.field(), Field.Store.YES));
});
yourIndexWriter.addDocument(document);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.