diff --git a/solr/core/src/java/org/apache/solr/request/SimpleFacets.java b/solr/core/src/java/org/apache/solr/request/SimpleFacets.java index 085b47e8a63..4a911d21a62 100644 --- a/solr/core/src/java/org/apache/solr/request/SimpleFacets.java +++ b/solr/core/src/java/org/apache/solr/request/SimpleFacets.java @@ -497,7 +497,16 @@ public class SimpleFacets { + FacetParams.FACET_EXCLUDETERMS + ") are not supported on numeric types"); } if (ft.isPointField() && mincount <= 0) { // default is mincount=0. See SOLR-10033 & SOLR-11174. - LOG.warn("Raising facet.mincount from " + mincount + " to 1, because field " + field + " is Points-based."); + String warningMessage + = "Raising facet.mincount from " + mincount + " to 1, because field " + field + " is Points-based."; + LOG.warn(warningMessage); + List warnings = (List)rb.rsp.getResponseHeader().get("warnings"); + if (null == warnings) { + warnings = new ArrayList<>(); + rb.rsp.getResponseHeader().add("warnings", warnings); + } + warnings.add(warningMessage); + mincount = 1; } counts = NumericFacets.getCounts(searcher, docs, field, offset, limit, mincount, missing, sort); diff --git a/solr/core/src/test/org/apache/solr/request/TestFaceting.java b/solr/core/src/test/org/apache/solr/request/TestFaceting.java index 32cb177fa0a..ff7d72013ef 100644 --- a/solr/core/src/test/org/apache/solr/request/TestFaceting.java +++ b/solr/core/src/test/org/apache/solr/request/TestFaceting.java @@ -356,8 +356,28 @@ public class TestFaceting extends SolrTestCaseJ4 { "//lst[@name='facet_fields']/lst[@name='f_td']/int[3][@name='-1.218']"); } + @Test + public void testFacetOverPointFieldWithMinCount0() { + String field = "f_" + new String[]{"i","l","f","d"}[random().nextInt(4)] + "_p"; + String expectedWarning = "Raising facet.mincount from 0 to 1, because field " + field + " is Points-based."; + SolrQueryRequest req = req("q", "id:1.0", + FacetParams.FACET, "true", + FacetParams.FACET_FIELD, field, + FacetParams.FACET_MINCOUNT, "0"); + assertQ(req + , "/response/lst[@name='responseHeader']/arr[@name='warnings']/str[.='" + expectedWarning + "']"); + + field = "f_" + new String[]{"is","ls","fs","ds"}[random().nextInt(4)] + "_p"; + expectedWarning = "Raising facet.mincount from 0 to 1, because field " + field + " is Points-based."; + req = req("q", "id:1.0", + FacetParams.FACET, "true", + FacetParams.FACET_FIELD, field, + FacetParams.FACET_MINCOUNT, "0"); + assertQ(req + , "/response/lst[@name='responseHeader']/arr[@name='warnings']/str[.='" + expectedWarning + "']"); + } - public void testSimpleFacetCountsWithMultipleConfigurationsForSameField() { + public void testSimpleFacetCountsWithMultipleConfigurationsForSameField() { clearIndex(); String fname = "trait_ss"; assertU(adoc("id", "42",