FunctionScoreQuery block-max bound drops top hits when the value field has a doc values skip index
Description
Since #16431, FunctionScoreQuery reports a block max score based on the DocValuesSkipper of the value field. When that field has a skip index (for example NumericDocValuesField.indexedField), the bound can be lower than the real score, so MaxScoreBulkScorer and BlockMaxConjunctionBulkScorer skip documents that belong in the top hits. There's no exception, CheckIndex is clean, and totalHits is reported as a lower bound, so the results look plausible.
In FunctionScoreWeight, getMaxScore returns innerMaxScore * valueMaxScore * boost, but score() is only the source value times the boost. FieldValuesSource doesn't need scores, so the wrapped query is created with COMPLETE_NO_SCORES. For a TermQuery that means getMaxScore is 0, and the whole bound becomes 0.
Reproduction: index 2000 docs with body:common, then one doc with body:rare and NumericDocValuesField.indexedField("val", 1_000_000), then:
Query q =
new BooleanQuery.Builder()
.add(
new FunctionScoreQuery(
new TermQuery(new Term("body", "rare")), DoubleValuesSource.fromLongField("val")),
BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term("body", "common")), BooleanClause.Occur.SHOULD)
.build();
searcher.search(q, 10); // doc 2000 (score 1000000) is missing
searcher.search(q, new TopScoreDocCollectorManager(10, Integer.MAX_VALUE)); // doc 2000 is first
Two more bounds from the same change can also end up below the real value:
DoubleValues.withDefaultforwardsin.getMaxScoreand ignoresmissingValueFieldValuesSource.getMaxScorecasts the bound to the nearest float, e.g. 16777217 becomes 16777216
The existing tests don't catch this because they index plain NumericDocValuesField without a skip index, so the finite-bound branch never runs.
Version and environment details
- Lucene main (11.0.0-SNAPSHOT), introduced by #16431, not in 10.6.0 or branch_10_6
- JDK 25.0.5.1 (Temurin), Linux