我在 Lucene 中添加了一个多值字段:
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
}
稍后,当我在某个类别中搜索项目时,一切都按预期进行,但是当我获得文档并执行以下操作时:
String categories= doc.getField("categories").stringValue();
我只获取该文档的最后插入值,而不是为该文档添加的所有值。
如何获取为该文档添加的所有值?
最佳答案
你在文档中添加的不是多值单字段,而是多个同名字段。最后你只检索一个字段。
使用 public final List<IndexableField> getFields()
的 Document
相反。
关于java - Lucene - 检索文档中多值字段的所有值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21049069/