Lucene - retrieve all values for a multi-valued field in a document(Lucene - 检索文档中多值字段的所有值)
问题描述
我在 Lucene 中添加了一个多值字段:
I added a field in Lucene which is multi-valued as such:
String categoriesForItem = getCategories(); // returns "category1, category2, cat3" from a DB call
String [] categoriesForItems = categoriesForItem.split(",";
for(String cat : categoriesForItems) {
doc.add(new StringField("categories", cat , Field.Store.YES)); // doc is a Document
}
稍后当我在某个类别中搜索项目时,一切都按预期工作,但是当我得到一个文档并执行以下操作时:
later when I am searching for items in a category everything works as expected, but when I get a Document and do:
String categories= doc.getField("categories").stringValue();
我只获取该文档的最后插入值,而不是为该文档添加的所有值.
I only get the last inserted value for that document rather than all the values that were added for that document.
如何获取为该文档添加的所有值?
How can I get all the values which were added for that document?
推荐答案
你添加到文档中的不是多值单字段,而是多个同名字段.最后,您只检索一个字段.
What you are adding to the document is not multi-valued single field, but multiple fields with the same name. At the end you are only retrieving one field.
使用 public final List
代替.Document
的 getFields()
Use public final List<IndexableField> getFields()
of Document
instead.
这篇关于Lucene - 检索文档中多值字段的所有值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Lucene - 检索文档中多值字段的所有值
基础教程推荐
- 如何使用 Java 创建 X509 证书? 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 降序排序:Java Map 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01