Apache Lucene open-source search software
SOLR-11836: FacetStream works with bucketSizeLimit of -1 which will fetch all the buckets
Varun Thackerd35d2063a817
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex f9e5b562b2f..c3ab65b5d28 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -339,6 +339,9 @@ Bug Fixes* SOLR-12733: SolrMetricReporterTest failure (Erick Erickson, David Smiley)+* SOLR-11836: FacetStream works with bucketSizeLimit of -1 which will fetch all the buckets.+ (Alfonso Muñoz-Pomer Fuentes via Varun Thacker)+Optimizations----------------------diff --git a/solr/solr-ref-guide/src/stream-source-reference.adoc b/solr/solr-ref-guide/src/stream-source-reference.adocindex 042463c94ad..c31639a3bf7 100644--- a/solr/solr-ref-guide/src/stream-source-reference.adoc+++ b/solr/solr-ref-guide/src/stream-source-reference.adoc@@ -131,7 +131,7 @@ The `facet` function provides aggregations that are rolled up over buckets. Unde* `q`: (Mandatory) The query to build the aggregations from.* `buckets`: (Mandatory) Comma separated list of fields to rollup over. The comma separated list represents the dimensions in a multi-dimensional rollup.* `bucketSorts`: Comma separated list of sorts to apply to each dimension in the buckets parameters. Sorts can be on the computed metrics or on the bucket values.-* `bucketSizeLimit`: The number of buckets to include. This value is applied to each dimension.+* `bucketSizeLimit`: The number of buckets to include. This value is applied to each dimension. '-1' will fetch all the buckets.* `metrics`: List of metrics to compute for the buckets. Currently supported metrics are `sum(col)`, `avg(col)`, `min(col)`, `max(col)`, `count(*)`.=== facet Syntaxdiff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/FacetStream.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/FacetStream.javaindex 4010ff42ebf..4564ba0cdc6 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/FacetStream.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/FacetStream.java@@ -161,8 +161,8 @@ public class FacetStream extends TupleStream implements Expressible {int limitInt = 0;try{limitInt = Integer.parseInt(limitStr);- if(limitInt <= 0){- throw new IOException(String.format(Locale.ROOT,"invalid expression %s - limit '%s' must be greater than 0.",expression, limitStr));+ if(limitInt <= 0 && limitInt != -1){+ throw new IOException(String.format(Locale.ROOT,"invalid expression %s - limit '%s' must be greater than 0 or -1.",expression, limitStr));}}catch(NumberFormatException e){@@ -223,6 +223,9 @@ public class FacetStream extends TupleStream implements Expressible {this.buckets = buckets;this.metrics = metrics;this.bucketSizeLimit = bucketSizeLimit;+ if (this.bucketSizeLimit == -1) {+ this.bucketSizeLimit = Integer.MAX_VALUE;+ }this.collection = collection;this.bucketSorts = bucketSorts;diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamingTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamingTest.javaindex 8f2110072b6..ea3ec36a69d 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamingTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamingTest.java@@ -1076,6 +1076,15 @@ public void testParallelRankStream() throws Exception {assertEquals(7.5, avgi.doubleValue(), 0.1);assertEquals(5.5, avgf.doubleValue(), 0.1);assertEquals(2, count.doubleValue(), 0.1);++ sorts[0] = new FieldComparator("a_s", ComparatorOrder.ASCENDING);++ facetStream = new FacetStream(zkHost, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, -1);+ facetStream.setStreamContext(streamContext);+ tuples = getTuples(facetStream);++ assertEquals(3, tuples.size());+} finally {solrClientCache.close();}