You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2021/05/18 16:48:13 UTC

[lucene-solr] branch branch_8x updated: LUCENE-9953: Make FacetResult#value accurate for LongValueFacetCounts multi-value doc cases (#2491)

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

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


The following commit(s) were added to refs/heads/branch_8x by this push:
     new 3a7387d  LUCENE-9953: Make FacetResult#value accurate for LongValueFacetCounts multi-value doc cases (#2491)
3a7387d is described below

commit 3a7387d039b49ca6dbad2184aebbd1f79ae24c41
Author: Greg Miller <gs...@gmail.com>
AuthorDate: Tue May 18 09:47:57 2021 -0700

    LUCENE-9953: Make FacetResult#value accurate for LongValueFacetCounts multi-value doc cases (#2491)
    
    Co-authored-by: Greg Miller <gm...@amazon.com>
---
 lucene/CHANGES.txt                                             |  4 ++++
 lucene/facet/src/java/org/apache/lucene/facet/FacetResult.java | 10 +++++++---
 .../src/java/org/apache/lucene/facet/LongValueFacetCounts.java |  8 ++++++--
 .../test/org/apache/lucene/facet/TestLongValueFacetCounts.java |  8 ++++----
 4 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index d85f088..9e62630 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -76,6 +76,10 @@ Bug Fixes
 
 * LUCENE-9958: Fixed performance regression for boolean queries that configure a
   minimum number of matching clauses. (Adrien Grand, Matt Weber)
+  
+* LUCENE-9953: LongValueFacetCounts should count each document at most once when determining
+  the total count for a dimension. Prior to this fix, multi-value docs could contribute a > 1
+  count to the dimension count. (Greg Miller)
 
 Other
 ---------------------
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/FacetResult.java b/lucene/facet/src/java/org/apache/lucene/facet/FacetResult.java
index 5ca221b..46b74c4 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/FacetResult.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/FacetResult.java
@@ -27,9 +27,13 @@ public final class FacetResult {
   /** Path whose children were requested. */
   public final String[] path;
 
-  /** Total value for this path (sum of all child counts, or
-   *  sum of all child values), even those not included in
-   *  the topN. */
+  /**
+   * Total number of documents containing a value for this path, even those not included in the
+   * topN. If a document contains multiple values for the same path, it will only be counted once in
+   * this value.
+   */
+  // TODO: This may not hold true for SSDV faceting, where docs can be counted more than
+  // once. We should fix this. See LUCENE-9952
   public final Number value;
 
   /** How many child labels were encountered. */
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/LongValueFacetCounts.java b/lucene/facet/src/java/org/apache/lucene/facet/LongValueFacetCounts.java
index e3e33cb..16e2c64 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/LongValueFacetCounts.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/LongValueFacetCounts.java
@@ -175,7 +175,9 @@ public class LongValueFacetCounts extends Facets {
       
         for (int doc = it.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = it.nextDoc()) {
           int limit = values.docValueCount();
-          totCount += limit;
+          if (limit > 0) {
+            totCount++;
+          }
           for (int i = 0; i < limit; i++) {
             increment(values.nextValue());
           }
@@ -239,7 +241,9 @@ public class LongValueFacetCounts extends Facets {
         int doc;
         while ((doc = values.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
           int limit = values.docValueCount();
-          totCount += limit;
+          if (limit > 0) {
+            totCount++;
+          }
           for (int i = 0; i < limit; i++) {
             increment(values.nextValue());
           }
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java b/lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
index 4aa370d..a23d789 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
@@ -390,7 +390,8 @@ public class TestLongValueFacetCounts extends LuceneTestCase {
       int expectedChildCount = 0;
       int expectedTotalCount = 0;
       for (int i = 0; i < valueCount; i++) {
-        if (values[i] != null) {
+        if (values[i] != null && values[i].length > 0) {
+          expectedTotalCount++;
           for (long value : values[i]) {
             Integer curCount = expected.get(value);
             if (curCount == null) {
@@ -398,7 +399,6 @@ public class TestLongValueFacetCounts extends LuceneTestCase {
               expectedChildCount++;
             }
             expected.put(value, curCount + 1);
-            expectedTotalCount++;
           }
         }
       }
@@ -471,9 +471,9 @@ public class TestLongValueFacetCounts extends LuceneTestCase {
       expectedChildCount = 0;
       int totCount = 0;
       for (int i = minId; i <= maxId; i++) {
-        if (values[i] != null) {
+        if (values[i] != null && values[i].length > 0) {
+          totCount++;
           for (long value : values[i]) {
-            totCount++;
             Integer curCount = expected.get(value);
             if (curCount == null) {
               expectedChildCount++;