i\'m using lucene to index documents and perform a search after which, i immediately delete them. all this can be considered as a somewhat atomic action that includes the f
IndexWriter
, IndexReader
and IndexSearcher
are thread-safe according to the api javadoc:
NOTE: IndexSearcher instances are completely thread safe, meaning multiple threads can call any of its methods, concurrently
NOTE: IndexReader instances are completely thread safe, meaning multiple threads can call any of its methods, concurrently.
NOTE: IndexWriter instances are completely thread safe, meaning multiple threads can call any of its methods, concurrently
Multiple read-only IndexReader
s can be opened, but it's better to share one (for performance reasons).
Only a single IndexWriter
can be opened (and it will create a write lock to prevent others from being opened on the same index). You can use IndexReader
to delete documents while IndexWriter
holds this lock. IndexReader
will always see the index as it was at the time when it was opened, changes done by the writer will be visible only after the writer commits them the reader is reopened.
Any number of IndexSearcher
s can be opened, but again it's better to share one. They can be used even while the index is being modified. Works the same as for IndexReader
(the changes are not visible until the searcher is reopened).