SOLR-13725: allow negative values for limit in TermsFacetMap

* when limit is negative all the facet values are returned
* allow mincount=0 in TermsFacetMap.
This commit is contained in:
Munendra S N 2019-09-21 11:03:51 +05:30
parent c22379253c
commit 59fe7b7d9f
3 changed files with 8 additions and 16 deletions

View File

@ -224,6 +224,8 @@ Bug Fixes
* SOLR-13780: Fix ClassCastException in NestableJsonFacet (Tiago Martinho de Barros, Munendra S N) * 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 Other Changes
---------------------- ----------------------

View File

@ -55,9 +55,6 @@ public class TermsFacetMap extends JsonFacetMap<TermsFacetMap> {
* Defaults to 10 if not specified. * Defaults to 10 if not specified.
*/ */
public TermsFacetMap setLimit(int maximumBuckets) { public TermsFacetMap setLimit(int maximumBuckets) {
if (maximumBuckets < 0) {
throw new IllegalArgumentException("Parameter 'maximumBuckets' must be non-negative");
}
put("limit", maximumBuckets); put("limit", maximumBuckets);
return this; return this;
} }
@ -147,8 +144,8 @@ public class TermsFacetMap extends JsonFacetMap<TermsFacetMap> {
* Defaults to 1 if not specified. * Defaults to 1 if not specified.
*/ */
public TermsFacetMap setMinCount(int minCount) { public TermsFacetMap setMinCount(int minCount) {
if (minCount < 1) { if (minCount < 0) {
throw new IllegalArgumentException("Parameter 'minCount' must be a positive integer"); throw new IllegalArgumentException("Parameter 'minCount' must be a non-negative integer");
} }
put("mincount", minCount); put("mincount", minCount);
return this; return this;

View File

@ -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 @Test
public void testStoresBucketLimitWithCorrectKey() { public void testStoresBucketLimitWithCorrectKey() {
final TermsFacetMap termsFacet = new TermsFacetMap(ANY_FIELD_NAME) final TermsFacetMap termsFacet = new TermsFacetMap(ANY_FIELD_NAME)
@ -129,9 +120,9 @@ public class TermsFacetMapTest extends SolrTestCaseJ4 {
public void testRejectInvalidMinCount() { public void testRejectInvalidMinCount() {
final Throwable thrown = expectThrows(IllegalArgumentException.class, () -> { final Throwable thrown = expectThrows(IllegalArgumentException.class, () -> {
final TermsFacetMap termsFacet = new TermsFacetMap(ANY_FIELD_NAME) 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 @Test
@ -139,6 +130,8 @@ public class TermsFacetMapTest extends SolrTestCaseJ4 {
final TermsFacetMap termsFacet = new TermsFacetMap(ANY_FIELD_NAME) final TermsFacetMap termsFacet = new TermsFacetMap(ANY_FIELD_NAME)
.setMinCount(6); .setMinCount(6);
assertEquals(6, termsFacet.get("mincount")); assertEquals(6, termsFacet.get("mincount"));
termsFacet.setMinCount(0);
assertEquals(0, termsFacet.get("mincount"));
} }
@Test @Test