nick-boss-tech opened a new pull request, #5147:
URL: https://github.com/apache/solr/pull/5147

   🤖 *AI text below* 🤖 *(posted on behalf of Nick Shanin)*
   
   https://issues.apache.org/jira/browse/SOLR-9124
   
   ## What happens today
   
   **Grouped distributed queries score with each shard's own term statistics, 
so grouped scores can differ from the same query on one node.**
   
   A grouped distributed query asks each shard for term statistics in its first 
stage ([createDistributedStats 
call](https://github.com/nick-boss-tech/solr/blob/cabedd1d968059215188f4e7563fb303241899ed/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java#L607)).
 The stages after that send the shard requests without the merged statistics 
([L626-L629](https://github.com/nick-boss-tech/solr/blob/cabedd1d968059215188f4e7563fb303241899ed/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java#L626-L629)).
 The code that handles grouped responses does not read the statistics the 
shards return 
([L668-L681](https://github.com/nick-boss-tech/solr/blob/cabedd1d968059215188f4e7563fb303241899ed/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java#L668-L681)).
   
   The links point to the merge-base commit `cabedd1d968`, the code before this 
change.
   
   ## What this change does
   
   **Grouped distributed queries that score now send the merged term statistics 
in the group stages, and they read the statistics the shards return.**
   
   - The group-stage requests carry the merged statistics when the query scores 
([L626-L636 at head 
`64b8256cde`](https://github.com/nick-boss-tech/solr/blob/64b8256cde72665c7053d741e9bb572955afbaa7/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java#L626-L636)).
 The stored-fields stage is skipped, since it does not score.
   - One helper decides whether a query needs distributed statistics. The first 
stage and the group stages both use it 
([L641-L645](https://github.com/nick-boss-tech/solr/blob/64b8256cde72665c7053d741e9bb572955afbaa7/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java#L641-L645)).
   - Grouped responses merge the returned statistics, as ungrouped responses 
already did 
([L682-L684](https://github.com/nick-boss-tech/solr/blob/64b8256cde72665c7053d741e9bb572955afbaa7/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java#L682-L684)).
   
   Behavior change, stated openly: a grouped distributed query that scores gets 
its scores from the merged statistics instead of each shard's own. Queries that 
do not score, and queries with distributed statistics turned off, are unchanged.
   
   ## Proof
   
   **Four stats cache test classes pass with the change. With the change 
reverted, one test fails, in `TestExactStatsCache`.**
   
   - Four stats cache test classes, 5 of 5 pass at head `17a279d4dce1`, 
verified 2026-10-09. The live head `64b8256cde` changes only the changelog 
title, so the code is the same there.
     - `TestDefaultStatsCache` 1 of 1.
     - `TestExactStatsCache` 2 of 2.
     - `TestLRUStatsCache` 1 of 1.
     - `TestExactSharedStatsCache` 1 of 1.
   - The grouped check is 
[checkGroupedScores](https://github.com/nick-boss-tech/solr/blob/64b8256cde72665c7053d741e9bb572955afbaa7/solr/core/src/test/org/apache/solr/search/stats/TestBaseStatsCache.java#L78-L95).
 It compares the control grouped query with the same query on the shards.
   - On the merge-base version of `QueryComponent.java`, with the branch's 
tests in place, the same run has 5 tests and one failure, in 
`TestExactStatsCache`. The failing check is that grouped scores from 
shard-local statistics differ from the control scores.
   
   ## Limits
   
   **Only the exact cache class fails without the change. The other cache 
classes do not show it.**
   
   - `TestLRUStatsCache` and `TestExactSharedStatsCache` run the same grouped 
check and pass without the change, so their runs do not show it. The change 
calls each cache's own `sendGlobalStats`, so its effect on those caches is not 
shown by a test.
   - `TestDefaultStatsCache` does not run the grouped check, because its hook 
is empty.
   - The proof covers the four stats cache classes only. No other test class 
was run for this change.
   
   Changelog: 
[changelog/unreleased/SOLR-9124-grouped-exact-stats.yml](https://github.com/nick-boss-tech/solr/blob/64b8256cde72665c7053d741e9bb572955afbaa7/changelog/unreleased/SOLR-9124-grouped-exact-stats.yml)
   
   ### AI assistance
   
   AI agents assisted with research, implementation, review, and drafting. Nick 
Shanin directed the work and takes responsibility for this contribution.
   


-- 
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]

Reply via email to