These are the shapes the query engine is built against.
- Queries are data (
TermQuery,BooleanQuerywith Must/Should/MustNot/Filter clauses,PhraseQuerywith slop,PrefixQuery,FuzzyQuery,RangeQuery,MatchAllQuery), with value equality and aBoost. AQueryVisitor<T>turns them into other things; execution is a visitor that produces aWeight, so execution code never edits the query classes. - Segment reader.
ISegmentReadergives a segment's parts:ITextFieldReader(term lookup, prefix enumeration, postings, per-document field length, field statistics),IColumnReader,IPointIndexReader,IStoredFieldsReader,ILiveDocs. Document ids are dense and local to a segment; the search context adds each segment's offset to make global ids. - Iterators and scorers.
DocIdSetIterator(NextDoc,Advance,Cost).ScoreraddsScore()and three hooks for block-max WAND:AdvanceShallow(target)andGetMaxScore(upTo)bound the score of a run of documents without decoding them, andSetMinCompetitiveScorelets a collector tell the scorer which scores no longer matter.PostingsIterator.ShallowAdvancereturns aBlockImpact(last document, maximum frequency, minimum field length): because BM25 grows with frequency and shrinks with length, those two values bound a block's best score. - Collectors.
TopScoreCollectorkeeps the best k by score with a total, deterministic order: higher score first, then lower global document id. NaN scores rank last. It allocates nothing per document and raises the scorer's threshold as the heap fills.CountCollectorneeds no scores. - Searcher.
IndexSearcherasks anIWeightFactoryfor a weight, walks each segment's scorer, skips deleted documents and feeds the collector, checking cancellation every 1,024 documents. - Totals.
TopDocs.TotalHitsis exact when every match is visited (ScoreMode.Complete) and a lower bound underScoreMode.TopScores. - Doubles in points.
SortableBits.Encodemaps a double to a long with the same order, so a single integer point index serves both numeric kinds.