Web / Apache Lucene Interview questions
Explain the execution flow of a search request in Lucene?
From the moment a query object is submitted to the moment ranked results come back, Lucene runs through a consistent per-segment pipeline:
- The Query is turned into a Weight, which is query-wide but not tied to any single segment.
- For each segment, the Weight produces a Scorer that can iterate matching documents in that segment and compute a score for each.
- A Collector (commonly a top-N collector) consumes the Scorer's output, keeping only the best-scoring documents it's seen so far.
- Once every segment has been processed, per-segment top results are merged into a single ranked TopDocs, which IndexSearcher returns to the caller.
This per-segment design is exactly what lets Lucene search segments in parallel and lets Elasticsearch/Solr distribute the equivalent work across shards.
More Related questions...