harshvardhanrp opened a new pull request, #17051: URL: https://github.com/apache/lucene/pull/17051
### Description Fixes #17050 The block-max support added to `FunctionScoreQuery` in #16431 can report a max score that is lower than the real score once the value field has a doc values skip index. When that happens, MaxScoreBulkScorer / BlockMaxConjunctionBulkScorer treat the clause as unable to compete and skip documents that should be in the top hits. Nothing fails, so you just get wrong top hits. The main problem is in `FunctionScoreWeight#getMaxScore`, which returned `innerMaxScore * valueMaxScore * boost`. But `score()` is just the source value times the boost, and the wrapped query's score is never part of it. For a source like `DoubleValuesSource.fromLongField` that doesn't need scores, the wrapped query is created with `COMPLETE_NO_SCORES`, so a TermQuery reports a max score of 0, which makes the whole bound 0. While looking at this I found two more places from the same change where the bound can end up below the value: - `DoubleValues.withDefault` forwarded `in.getMaxScore` but ignored the missing value, so a doc without a value could score above the bound - the field source in `DoubleValuesSource` cast the bound to the nearest float, which can round down, e.g. 16777217 becomes 16777216 Changes: - `FunctionScoreQuery`: the bound is now `max(valueMaxScore, 0) * boost`, matching what `score()` computes - `DoubleValues.withDefault`: the bound also includes the missing value - `DoubleValuesSource`: the bound is rounded up when the float cast rounds it down Tests: I added two tests to `TestFunctionScoreQuery` and two to `TestDoubleValuesSource`. All four fail without the fix and pass with it. The existing block-max tests didn't catch this because they index plain `NumericDocValuesField`, which has no skip index, so the finite-bound path never ran. Two related things I noticed but left out to keep this focused: - if the value field has a NaN, the bound becomes NaN, and with assertions enabled WANDScorer trips `assert Float.isNaN(maxScore) == false` - `fromDoubleField` / `fromFloatField` treat raw IEEE bits as increasing, which doesn't hold for negative values. FunctionScoreQuery isn't affected after this change because negative values score 0, but `DoubleValues#getMaxScore` itself can still be off for blocks with only negative values #16431 hasn't been released yet, so I didn't add a separate CHANGES entry. I'm happy to add one or update the existing entry if that's preferred. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
