I have a few basic questions regarding the usage of SearcherManager with IndexWriter.
I need to periodically re-build the Lucene index in the application and currently it happens on a different thread other than the one that serves the search requests.
- Can I use the same IndexWriter instance through the lifetime of the application to rebuild the index periodically? Currently, I create / open it once during the startup and just call
IndexWriter#commit
whenever a new index is built. - I'm using
SearcherManager
to acquire and releaseIndexSearcher
instances for each search request. After the index is periodically built, I'm planning to useSearcherManager#maybeRefresh
method to get refreshedIndexSearcher
instances.SearcherManager instance is also created once during the startup and I intend to maintain it through out. - I do not close the
IndexWriter
orSearcherManager
throughout the app's lifetime.
Now for the questions,
- If I create a new IndexWriter every time I need to rebuild the index, will
SearcherManager#maybeRefresh
be able to detect that it's a new IndexWriter Instance? Or do I need to create a new SearcherManager using the newly created IndexWriter ? - What's the difference between creating a
SearcherManager
instance using anIndexWriter
, creating it using aDirectoryReader
or creating it using aDirectory
?