Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

updating lucene index

Tags:

lucene

What is the best way to update an existing Lucene index. I dont't just have to add/delete documents from it, rather update the existing documents.

like image 364
Akhil Avatar asked May 16 '10 03:05

Akhil


1 Answers

You will have to open the index without overwriting thus:

IndexWriter writer = new IndexWriter("MyIndexPath",analyzer, false);

The false flag at the end tells it to open in append mode.

The writer has an UpdateDocument method

writer.UpdateDocument(new Term("IDField",id), doc);

the id field should be some unique document identifier such as filename or file number etc.

like image 166
Mikos Avatar answered Oct 17 '22 17:10

Mikos