diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 8d04bc1e7ce..878faac672e 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -137,6 +137,9 @@ Bug Fixes * LUCENE-9031: UnsupportedOperationException on MatchesIterator.getQuery() (Alan Woodward, Mikhail Khludnev) +* LUCENE-8996: maxScore was sometimes missing from distributed grouped responses. + (Julien Massenet, Diego Ceccarelli, Munendra S N, Christine Poerschke) + Other * LUCENE-8979: Code Cleanup: Use entryset for map iteration wherever possible. - Part 2 (Koen De Groote) diff --git a/lucene/grouping/src/java/org/apache/lucene/search/grouping/TopGroups.java b/lucene/grouping/src/java/org/apache/lucene/search/grouping/TopGroups.java index ae1daf87ac4..b14e6753629 100644 --- a/lucene/grouping/src/java/org/apache/lucene/search/grouping/TopGroups.java +++ b/lucene/grouping/src/java/org/apache/lucene/search/grouping/TopGroups.java @@ -80,6 +80,19 @@ public class TopGroups { Avg, } + /** + * If either value is NaN then return the other value, otherwise + * return the greater of the two values by calling Math.max. + * @param a - one value + * @param b - another value + * @return ignoring any NaN return the greater of a and b + */ + private static float nonNANmax(float a, float b) { + if (Float.isNaN(a)) return b; + if (Float.isNaN(b)) return a; + return Math.max(a, b); + } + /** Merges an array of TopGroups, for example obtained * from the second-pass collector across multiple * shards. Each TopGroups must have been sorted by the @@ -135,12 +148,12 @@ public class TopGroups { } else { shardTopDocs = new TopFieldDocs[shardGroups.length]; } - float totalMaxScore = Float.MIN_VALUE; + float totalMaxScore = Float.NaN; for(int groupIDX=0;groupIDX