From a11457b4e636f939bf1c1592c6378627ec4dd1e3 Mon Sep 17 00:00:00 2001 From: Greg Miller Date: Sat, 7 Aug 2021 10:20:49 -0700 Subject: [PATCH] LUCENE-10047: Fix value de-duping check in LongValueFacetCounts and RangeFacetCounts (#237) --- lucene/CHANGES.txt | 3 +++ .../org/apache/lucene/facet/LongValueFacetCounts.java | 8 ++++---- .../org/apache/lucene/facet/range/RangeFacetCounts.java | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 2605de8be51..4e1a8ff572c 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -281,6 +281,9 @@ Bug fixes * LUCENE-9823: Prevent unsafe rewrites for SynonymQuery and CombinedFieldQuery. Before, rewriting could slightly change the scoring when weights were specified. (Naoto Minami via Julie Tibshirani) +* LUCENE-10047: Fix a value de-duping bug in LongValueFacetCounts and RangeFacetCounts + (Greg Miller) + Changes in Backwards Compatibility Policy * LUCENE-9904: regenerated UAX29URLEmailTokenizer and the corresponding analyzer with up-to-date top 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 864e2265cf2..56e0286a926 100644 --- a/lucene/facet/src/java/org/apache/lucene/facet/LongValueFacetCounts.java +++ b/lucene/facet/src/java/org/apache/lucene/facet/LongValueFacetCounts.java @@ -162,11 +162,11 @@ public class LongValueFacetCounts extends Facets { if (limit > 0) { totCount++; } - long previousValue = -1; + long previousValue = 0; for (int i = 0; i < limit; i++) { long value = multiValues.nextValue(); // do not increment the count for duplicate values - if (value != previousValue) { + if (i == 0 || value != previousValue) { increment(value); previousValue = value; } @@ -214,11 +214,11 @@ public class LongValueFacetCounts extends Facets { if (limit > 0) { totCount++; } - long previousValue = -1; + long previousValue = 0; for (int i = 0; i < limit; i++) { long value = multiValues.nextValue(); // do not increment the count for duplicate values - if (value != previousValue) { + if (i == 0 || value != previousValue) { increment(value); previousValue = value; } diff --git a/lucene/facet/src/java/org/apache/lucene/facet/range/RangeFacetCounts.java b/lucene/facet/src/java/org/apache/lucene/facet/range/RangeFacetCounts.java index 3f56c78fa3a..fc376c5b0c7 100644 --- a/lucene/facet/src/java/org/apache/lucene/facet/range/RangeFacetCounts.java +++ b/lucene/facet/src/java/org/apache/lucene/facet/range/RangeFacetCounts.java @@ -193,10 +193,10 @@ abstract class RangeFacetCounts extends Facets { totCount++; } else { counter.startMultiValuedDoc(); - long previous = -1; + long previous = 0; for (int j = 0; j < limit; j++) { long val = mapDocValue(multiValues.nextValue()); - if (val != previous) { + if (j == 0 || val != previous) { counter.addMultiValued(val); previous = val; }