Reputation: 25790
In my Spring/Lucene application I'm using Lucene IndexWriter
, TrackingIndexWriter
, SearcherManager
and ControlledRealTimeReopenThread
.
Right now I'm trying to index a thousands of a documents. For this purpose I have added Apache ActiveMQ and indexing every document in a separate message consumer.
I noticed one serious issue - in case of abnormal JVM termination after the next application restart my Lucene index is empty because IndexWriter.commit()
operation was not performed.
If I invoke IndexWriter.commit()
after each trackingIndexWriter.addDocument(document);
everything works fine.
I don't think it is a good idea to use IndexWriter.commit()
after each trackingIndexWriter.addDocument(document);
especially from performance point of view.
How to correctly manage my index in order to not lose it after application abnormal termination?
Upvotes: 0
Views: 356
Reputation: 915
IndexWriter.commit() will only flush the data. It would neither optimise your index nor close the writer.
The same Indexwriter can be used again to add more data.
Do not call IndexWriter.close() which not only flushes the data but also optimize the index and that operation is considerably slow.
Once you are done then finally you can close to do optimization.
So from performance point of view it is ok to commit after every document addition.
Upvotes: 1