我想阅读每一个索引。我想阅读并打印以控制索引中的单个词条。 (我不想看到卢克的内容)。我必须使用类IndexReader
?我想阅读我的索引与Lucene的单个术语
有人可以帮助我吗?
我试图做的:
iReader = IndexReader.open(directory);
int num = iReader.numDocs();
for (int i = 0; i < num; i++)
{
if (! iReader.isDeleted(i))
{
org.apache.lucene.document.Document d = iReader.document(i);
System.out.println("d=" +d.getField("title").tokenStreamValue());
}
}
org.apache.lucene.document.Document doc = new org.apache.lucene.document.Document();
//aggiungo tutti i documenti
Field title = new Field(
"title",
testDoc.title,
Field.Store.YES,
Field.Index.ANALYZED,
Field.TermVector.WITH_POSITIONS_OFFSETS);
doc.add(title);
Field content = new Field(
"content",
testDoc.content,
Field.Store.YES,
Field.Index.ANALYZED,
Field.TermVector.WITH_POSITIONS_OFFSETS);
doc.add(content);
iWriter.addDocument(doc);
但d = null;
哪儿我去错了吗? 我想检索术语到我索引的字段标题...
非常感谢。
我亚伦感谢您的回复。我修改上面的帖子。错误在哪里? – JackDaniels 2011-01-14 14:05:21