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#commitwhenever a new index is built. - I'm using
SearcherManagerto acquire and releaseIndexSearcherinstances for each search request. After the index is periodically built, I'm planning to useSearcherManager#maybeRefreshmethod to get refreshedIndexSearcherinstances.SearcherManager instance is also created once during the startup and I intend to maintain it through out. - I do not close the
IndexWriterorSearcherManagerthroughout the app's lifetime.
Now for the questions,
- If I create a new IndexWriter every time I need to rebuild the index, will
SearcherManager#maybeRefreshbe 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
SearcherManagerinstance using anIndexWriter, creating it using aDirectoryReaderor creating it using aDirectory?