You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by cp...@apache.org on 2019/10/23 11:52:47 UTC

[lucene-solr] 02/02: LUCENE-8996: maxScore was sometimes missing from distributed grouped responses. (Julien Massenet, Diego Ceccarelli, Christine Poerschke)

This is an automated email from the ASF dual-hosted git repository.

cpoerschke pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit fb37f89af27d881efb0f7b40eff2dc76ef5bc2c4
Author: Christine Poerschke <cp...@apache.org>
AuthorDate: Wed Oct 23 12:08:42 2019 +0100

    LUCENE-8996: maxScore was sometimes missing from distributed grouped responses.
    (Julien Massenet, Diego Ceccarelli, Christine Poerschke)
    
    Resolved Conflicts:
    	lucene/grouping/src/java/org/apache/lucene/search/grouping/TopGroups.java
---
 lucene/CHANGES.txt                                      |  3 +++
 .../org/apache/lucene/search/grouping/TopGroups.java    | 17 +++++++++++++++--
 .../apache/lucene/search/grouping/TopGroupsTest.java    |  4 ----
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 1d9d4b9..1fec234 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -170,6 +170,9 @@ Bug Fixes
   subclauses, and then pull SHOULD, MUST_NOT and FILTER visitors from it rather than from
   the parent.  (Alan Woodward)
 
+* LUCENE-8996: maxScore was sometimes missing from distributed grouped responses.
+  (Julien Massenet, Diego Ceccarelli, Christine Poerschke)
+
 Other
 
 * LUCENE-8778 LUCENE-8911 LUCENE-8957: Define analyzer SPI names as static final fields and document the names in Javadocs.
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 71338f9..af1fffd 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<T> {
     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
@@ -169,7 +182,7 @@ public class TopGroups<T> {
               shardGroupDocs.scoreDocs,
               docSort.getSort());
         }
-        maxScore = Math.max(maxScore, shardGroupDocs.maxScore);
+        maxScore =  nonNANmax(maxScore, shardGroupDocs.maxScore);
         assert shardGroupDocs.totalHits.relation == Relation.EQUAL_TO;
         totalHits += shardGroupDocs.totalHits.value;
         scoreSum += shardGroupDocs.score;
@@ -223,7 +236,7 @@ public class TopGroups<T> {
                                                    mergedScoreDocs,
                                                    groupValue,
                                                    shardGroups[0].groups[groupIDX].groupSortValues);
-      totalMaxScore = Math.max(totalMaxScore, maxScore);
+      totalMaxScore = nonNANmax(totalMaxScore, maxScore);
     }
 
     if (totalGroupCount != null) {
diff --git a/lucene/grouping/src/test/org/apache/lucene/search/grouping/TopGroupsTest.java b/lucene/grouping/src/test/org/apache/lucene/search/grouping/TopGroupsTest.java
index 8fb661d..e160bf4 100644
--- a/lucene/grouping/src/test/org/apache/lucene/search/grouping/TopGroupsTest.java
+++ b/lucene/grouping/src/test/org/apache/lucene/search/grouping/TopGroupsTest.java
@@ -21,16 +21,12 @@ import org.apache.lucene.search.Sort;
 import org.apache.lucene.search.TotalHits;
 import org.apache.lucene.util.LuceneTestCase;
 
-import org.junit.Ignore;
-
 public class TopGroupsTest extends LuceneTestCase {
 
-  @Ignore // https://issues.apache.org/jira/browse/LUCENE-8996
   public void testAllGroupsEmptyInSecondPass() {
     narrativeMergeTestImplementation(false, false, false, false);
   }
 
-  @Ignore // https://issues.apache.org/jira/browse/LUCENE-8996
   public void testSomeGroupsEmptyInSecondPass() {
     narrativeMergeTestImplementation(false, false, false, true);
     narrativeMergeTestImplementation(false, false, true, false);