Web / Apache Lucene Interview questions
Explain the lifecycle of an IndexSearcher across an NRT reopen?
Rather than closing and reopening searchers manually, Lucene's SearcherManager (a ReferenceManager implementation) manages this lifecycle so no in-flight search ever sees a reader closed out from under it.
- Callers acquire() the current searcher for use and must release() it when done - this reference counting is what keeps it alive during a search.
- Periodically (or on a schedule), maybeRefresh() checks if the underlying IndexWriter has new segments and, if so, opens a new IndexSearcher reflecting them.
- New acquire() calls after a refresh get the new searcher; searches already in flight on the old one continue safely.
- The old searcher is only actually closed once every caller holding a reference has released it.
This pattern is exactly what makes NRT search safe under concurrent load - no query is ever handed a reader that gets closed mid-search.
More Related questions...