Prev Next

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.

sequenceDiagram participant App participant SearcherManager participant OldSearcher participant NewSearcher App->>SearcherManager: acquire() SearcherManager-->>App: OldSearcher (in use) App->>SearcherManager: maybeRefresh() SearcherManager->>NewSearcher: open from writer's latest state App->>SearcherManager: acquire() SearcherManager-->>App: NewSearcher App->>SearcherManager: release(OldSearcher) SearcherManager->>OldSearcher: close once refcount hits zero
  1. Callers acquire() the current searcher for use and must release() it when done - this reference counting is what keeps it alive during a search.
  2. Periodically (or on a schedule), maybeRefresh() checks if the underlying IndexWriter has new segments and, if so, opens a new IndexSearcher reflecting them.
  3. New acquire() calls after a refresh get the new searcher; searches already in flight on the old one continue safely.
  4. 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.

SearcherManager ensures an old searcher is closed only after:
Calling maybeRefresh() checks whether:

More Related questions...

What is Apache Lucene? What is an inverted index in Lucene? What is a Lucene Document? What are Fields in a Lucene Document? What is an Analyzer in Lucene? What is a Tokenizer in Lucene? What is a TokenFilter in Lucene? What is the purpose of the IndexWriter class? What is the purpose of the IndexSearcher class? What are the different types of Field in Lucene? What is a Lucene Directory? Define a Lucene Segment? Describe the role of the QueryParser in Lucene? List common built-in Analyzers in Lucene? What is a Term in Lucene? What is the difference between StringField and TextField? What is the difference between IndexWriter and IndexWriterConfig? Why do we use Analyzers with different tokenization strategies? How does Lucene score documents (TF-IDF vs BM25)? When should you use StandardAnalyzer vs a custom Analyzer? What is the difference between a TermQuery and a PhraseQuery? How does the inverted index handle updates and deletes? Explain the lifecycle of an IndexWriter commit? What happens when you call IndexWriter.forceMerge()? How do you optimize a Lucene index for search performance? What is the difference between Stored fields and Indexed fields? Why should you use Norms and when can they be disabled? How does Lucene handle segment merging? What is the difference between NRT search and a normal commit? How do you troubleshoot slow queries in Lucene? Explain the difference between BooleanQuery and BooleanClause? What is the difference between Lucene and Elasticsearch or Solr? How does faceting work conceptually in Lucene? Which is better and why: FuzzyQuery vs WildcardQuery for typo tolerance? Explain the execution flow of a search request in Lucene? Explain the internal working of Lucene's BM25Similarity? Explain the internal working of segment merging and merge policies? How do you implement a custom Analyzer chain? Explain the internal working of Lucene's codec architecture? How can you optimize indexing throughput for large-scale data? Explain the lifecycle of an IndexSearcher across an NRT reopen? What is the difference between DocValues and stored fields for sorting or faceting? Explain the internal working of Lucene's point-based fields (BKD tree) for range queries? How do you implement custom scoring using Lucene's Similarity API? Explain the internal working of the SpanQuery family? How does Lucene ensure durability and crash recovery? What is the difference between per-field similarity and global similarity configuration? Explain the internal working of Lucene's MMapDirectory I/O? How do you troubleshoot OOM errors in a Lucene-based application? Explain how Lucene's architecture influences distributed search systems like Solr and Elasticsearch?
Show more question and Answers...


Comments & Discussions