Apache Solr open-source search software
SOLR-11363: handle repeated values in points docvalues fields
yonik7cc9ee65633f
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 69710a68c4d..885f1f65e50 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -133,6 +133,10 @@ Bug Fixes* SOLR-11348: Fix the DIH database example (James Dyer)+* SOLR-11363: JSON Facet API: repeated values in a numeric points field with docValues enabled+ were double counted. (Hossman, yonik)++Optimizations----------------------diff --git a/solr/core/src/java/org/apache/solr/search/facet/FacetFieldProcessorByHashDV.java b/solr/core/src/java/org/apache/solr/search/facet/FacetFieldProcessorByHashDV.javaindex 4237c31d028..2383a14dcd4 100644--- a/solr/core/src/java/org/apache/solr/search/facet/FacetFieldProcessorByHashDV.java+++ b/solr/core/src/java/org/apache/solr/search/facet/FacetFieldProcessorByHashDV.java@@ -390,9 +390,16 @@ class FacetFieldProcessorByHashDV extends FacetFieldProcessor {values.advance(segDoc);}if (segDoc == values.docID()) {- for (int i = 0; i < values.docValueCount(); i++) {- collectValFirstPhase(segDoc, values.nextValue());+ long l = values.nextValue(); // This document must have at least one value+ collectValFirstPhase(segDoc, l);+ for (int i = 1; i < values.docValueCount(); i++) {+ long lnew = values.nextValue();+ if (lnew != l) { // Skip the value if it's equal to the last one, we don't want to double-count it+ collectValFirstPhase(segDoc, lnew);+ }+ l = lnew;}+}}});diff --git a/solr/core/src/java/org/apache/solr/search/facet/HLLAgg.java b/solr/core/src/java/org/apache/solr/search/facet/HLLAgg.javaindex 3c55329c64b..85964f7117b 100644--- a/solr/core/src/java/org/apache/solr/search/facet/HLLAgg.java+++ b/solr/core/src/java/org/apache/solr/search/facet/HLLAgg.java@@ -235,6 +235,7 @@ public class HLLAgg extends StrAggValueSource {@Overrideprotected void collectValues(int doc, HLL hll) throws IOException {for (int i = 0; i < values.docValueCount(); i++) {+ // duplicates may be produced for a single doc, but won't matter here.long val = values.nextValue();long hash = Hash.fmix64(val);hll.addRaw(hash);diff --git a/solr/core/src/java/org/apache/solr/search/facet/UniqueAgg.java b/solr/core/src/java/org/apache/solr/search/facet/UniqueAgg.javaindex 454197595b7..d858b5bd45c 100644--- a/solr/core/src/java/org/apache/solr/search/facet/UniqueAgg.java+++ b/solr/core/src/java/org/apache/solr/search/facet/UniqueAgg.java@@ -254,6 +254,7 @@ public class UniqueAgg extends StrAggValueSource {@Overrideprotected void collectValues(int doc, LongSet set) throws IOException {for (int i = 0; i < values.docValueCount(); i++) {+ // duplicates may be produced for a single doc, but won't matter here.set.add(values.nextValue());}}diff --git a/solr/core/src/java/org/apache/solr/search/join/GraphPointsCollector.java b/solr/core/src/java/org/apache/solr/search/join/GraphPointsCollector.javaindex 290136a13d1..e868465037d 100644--- a/solr/core/src/java/org/apache/solr/search/join/GraphPointsCollector.java+++ b/solr/core/src/java/org/apache/solr/search/join/GraphPointsCollector.java@@ -60,6 +60,7 @@ public class GraphPointsCollector extends GraphEdgeCollector {if (valuesDoc == doc) {int count = values.docValueCount();for (int i = 0; i < count; i++) {+ // duplicates may be produced for a single doc, but won't matter here.long v = values.nextValue();set.add(v);}diff --git a/solr/core/src/test/org/apache/solr/cloud/TestCloudJSONFacetJoinDomain.java b/solr/core/src/test/org/apache/solr/cloud/TestCloudJSONFacetJoinDomain.javaindex e18312cca0e..48de49a4a8c 100644--- a/solr/core/src/test/org/apache/solr/cloud/TestCloudJSONFacetJoinDomain.java+++ b/solr/core/src/test/org/apache/solr/cloud/TestCloudJSONFacetJoinDomain.java@@ -17,7 +17,6 @@package org.apache.solr.cloud;import java.io.IOException;-import java.lang.invoke.MethodHandles;import java.nio.file.Path;import java.nio.file.Paths;@@ -29,10 +28,9 @@ import java.util.List;import java.util.Map;import java.util.Random;import java.util.concurrent.atomic.AtomicInteger;-+import org.apache.commons.lang.StringUtils;import org.apache.lucene.util.TestUtil;-import org.apache.solr.SolrTestCaseJ4.SuppressPointFields;import org.apache.solr.client.solrj.SolrClient;import org.apache.solr.client.solrj.SolrServerException;import org.apache.solr.client.solrj.embedded.JettySolrRunner;@@ -46,7 +44,6 @@ import org.apache.solr.common.SolrInputDocument;import org.apache.solr.common.params.ModifiableSolrParams;import org.apache.solr.common.params.SolrParams;import org.apache.solr.common.util.NamedList;-import org.junit.AfterClass;import org.junit.BeforeClass;import org.slf4j.Logger;@@ -62,7 +59,6 @@ import org.slf4j.LoggerFactory;** @see TestCloudPivotFacet*/-@SuppressPointFields(bugUrl="https://issues.apache.org/jira/browse/SOLR-10939")public class TestCloudJSONFacetJoinDomain extends SolrCloudTestCase {private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());@@ -600,9 +596,21 @@ public class TestCloudJSONFacetJoinDomain extends SolrCloudTestCase {final String[] suffixes = random().nextBoolean() ? STR_FIELD_SUFFIXES : INT_FIELD_SUFFIXES;final boolean noJoin = random().nextBoolean();- final String from = noJoin ? null : field(suffixes, random().nextInt(MAX_FIELD_NUM));- final String to = noJoin ? null : field(suffixes, random().nextInt(MAX_FIELD_NUM));-++ String from = null;+ String to = null;+ for (;;) {+ if (noJoin) break;+ from = field(suffixes, random().nextInt(MAX_FIELD_NUM));+ to = field(suffixes, random().nextInt(MAX_FIELD_NUM));+ // HACK: joined numeric point fields need docValues.. for now just skip _is fields if we are dealing with points.+ if (Boolean.getBoolean(NUMERIC_POINTS_SYSPROP) && (from.endsWith("_is") || to.endsWith("_is")))+ {+ continue;+ }+ break;+ }+// keep it simple, only filter on string fields - not point of testfinal String filterField = strfield(random().nextInt(MAX_FIELD_NUM));diff --git a/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java b/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.javaindex 33d7fa89c78..a1c8cf7ae0d 100644--- a/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java+++ b/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java@@ -42,6 +42,10 @@ import org.junit.AfterClass;import org.junit.BeforeClass;import org.junit.Test;+// Related tests:+// TestCloudJSONFacetJoinDomain for random field faceting tests with domain modifications+// TestJsonFacetRefinement for refinement tests+@LuceneTestCase.SuppressCodecs({"Lucene3x","Lucene40","Lucene41","Lucene42","Lucene45","Appending"})public class TestJsonFacets extends SolrTestCaseHS {@@ -208,6 +212,28 @@ public class TestJsonFacets extends SolrTestCaseHS {client.commit();}+ @Test+ public void testRepeatedNumerics() throws Exception {+ Client client = Client.localClient();+ String field = "num_is"; // docValues of multi-valued points field can contain duplicate values... make sure they don't mess up our counts.+ client.add(sdoc("id", "1", "cat_s", "A", "where_s", "NY", "num_d", "4", "num_i", "2", "val_b", "true", "sparse_s", "one", field,"0", field,"0"), null);+ client.commit();++ client.testJQ(params("q", "id:1", "field", field+ , "json.facet", "{" ++ "f1:{terms:${field}}" ++ ",f2:'hll(${field})'" ++ ",f3:{type:range, field:${field}, start:0, end:1, gap:1}" ++ "}"+ )+ , "facets=={count:1, " ++ "f1:{buckets:[{val:0, count:1}]}" ++ ",f2:1" ++ ",f3:{buckets:[{val:0, count:1}]}" ++ "}"+ );+ }+public void testDomainJoinSelf() throws Exception {Client client = Client.localClient();indexSimple(client);