I want to read every single index. I want to read and print to console the single term in my index. (I don't want to view the contents with Luke). Must I use the class IndexReader
?
Can someone help me?
I tried to do:
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);
but d = null;
Where did I go wrong?
I want to retrieve the term to the Field title that I indexed...
Thanks very much.