Java Lucene-检索文档中多值字段的所有值

Java Lucene-检索文档中多值字段的所有值,java,lucene,document,Java,Lucene,Document,我在Lucene中添加了一个多值字段: String categoriesForItem = getCategories(); // returns "category1, category2, cat3" from a DB call String [] categoriesForItems = categoriesForItem.split(","; for(String cat : categoriesForItems) { doc.add(new StringField("c

我在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(); 
我只获取该文档的最后一个插入值,而不是为该文档添加的所有值


如何获取为该文档添加的所有值?

您添加到文档中的不是多值单字段,而是具有相同名称的多个字段。最后,您只检索一个字段

使用
文档的
公共最终列表getFields()

使用
doc.getValues(“类别”)