From 59fe7b7d9fc7bbc26e761a6a51a32803eb024c3e Mon Sep 17 00:00:00 2001 From: Munendra S N Date: Sat, 21 Sep 2019 11:03:51 +0530 Subject: [PATCH] SOLR-13725: allow negative values for limit in TermsFacetMap * when limit is negative all the facet values are returned * allow mincount=0 in TermsFacetMap. --- solr/CHANGES.txt | 2 ++ .../client/solrj/request/json/TermsFacetMap.java | 7 ++----- .../solrj/request/json/TermsFacetMapTest.java | 15 ++++----------- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 883732e117b..9537dfbae05 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -224,6 +224,8 @@ Bug Fixes * SOLR-13780: Fix ClassCastException in NestableJsonFacet (Tiago Martinho de Barros, Munendra S N) +* SOLR-13725: Allow negative values for limit in TermsFacetMap (Richard Walker, Munendra S N) + Other Changes ---------------------- diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/json/TermsFacetMap.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/json/TermsFacetMap.java index ea7c2fd2c70..c088d45b8e4 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/json/TermsFacetMap.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/json/TermsFacetMap.java @@ -55,9 +55,6 @@ public class TermsFacetMap extends JsonFacetMap { * Defaults to 10 if not specified. */ public TermsFacetMap setLimit(int maximumBuckets) { - if (maximumBuckets < 0) { - throw new IllegalArgumentException("Parameter 'maximumBuckets' must be non-negative"); - } put("limit", maximumBuckets); return this; } @@ -147,8 +144,8 @@ public class TermsFacetMap extends JsonFacetMap { * Defaults to 1 if not specified. */ public TermsFacetMap setMinCount(int minCount) { - if (minCount < 1) { - throw new IllegalArgumentException("Parameter 'minCount' must be a positive integer"); + if (minCount < 0) { + throw new IllegalArgumentException("Parameter 'minCount' must be a non-negative integer"); } put("mincount", minCount); return this; diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/TermsFacetMapTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/TermsFacetMapTest.java index 0d06e590e6f..7028326918c 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/TermsFacetMapTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/TermsFacetMapTest.java @@ -54,15 +54,6 @@ public class TermsFacetMapTest extends SolrTestCaseJ4 { } - @Test - public void testRejectsNegativeBucketLimit() { - final Throwable thrown = expectThrows(IllegalArgumentException.class, () -> { - final TermsFacetMap termsFacet = new TermsFacetMap(ANY_FIELD_NAME) - .setLimit(-1); - }); - assertThat(thrown.getMessage(), containsString("must be non-negative")); - } - @Test public void testStoresBucketLimitWithCorrectKey() { final TermsFacetMap termsFacet = new TermsFacetMap(ANY_FIELD_NAME) @@ -129,9 +120,9 @@ public class TermsFacetMapTest extends SolrTestCaseJ4 { public void testRejectInvalidMinCount() { final Throwable thrown = expectThrows(IllegalArgumentException.class, () -> { final TermsFacetMap termsFacet = new TermsFacetMap(ANY_FIELD_NAME) - .setMinCount(0); + .setMinCount(-1); }); - assertThat(thrown.getMessage(), containsString("must be a positive integer")); + assertThat(thrown.getMessage(), containsString("must be a non-negative integer")); } @Test @@ -139,6 +130,8 @@ public class TermsFacetMapTest extends SolrTestCaseJ4 { final TermsFacetMap termsFacet = new TermsFacetMap(ANY_FIELD_NAME) .setMinCount(6); assertEquals(6, termsFacet.get("mincount")); + termsFacet.setMinCount(0); + assertEquals(0, termsFacet.get("mincount")); } @Test