【发布时间】:2014-10-04 04:47:17
【问题描述】:
我需要显示给定 Lucene 索引的所有术语。
public void addDocuments(IndexWriter indexWriter) throws IOException {
Document doc1 = new Document();
doc1.add(new TextField("title", "harrypotter", Field.Store.YES));
indexWriter.addDocument(doc1);
Document doc2 = new Document();
doc2.add(new TextField("title", "luceneinaction", Field.Store.YES));
indexWriter.addDocument(doc2);
Document doc3 = new Document();
doc3.add(new TextField("title", "harrypotter", Field.Store.YES));
indexWriter.addDocument(doc3);
}
我正在尝试这个:
Fields fields = MultiFields.getFields(reader);
Terms terms = fields.terms("title");
TermsEnum iterator = terms.iterator(null);
BytesRef byteRef = null;
while((byteRef = iterator.next()) != null) {
System.out.println(byteRef.utf8ToString());
}
然而,这给了我唯一的术语:
harrypotter
luceneinaction
有没有得到所有的条款(也是重复的)?还是术语总是唯一的?
谢谢。
PS:Lucene版本是4.0。
【问题讨论】:
-
这似乎不是主要问题。你到底想做什么?
标签: java search lucene full-text-search