diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index ed4d1e467fd..3f8f2e3b1f3 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -590,6 +590,9 @@ Other Changes * SOLR-10919: ord & rord functions give confusing errors with PointFields. (hossman, Steve Rowe) +* SOLR-10847: Provide a clear exception when attempting to use the terms component with points fields. + (hossman, Steve Rowe) + ================== 6.7.0 ================== Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release. diff --git a/solr/core/src/java/org/apache/solr/handler/component/TermsComponent.java b/solr/core/src/java/org/apache/solr/handler/component/TermsComponent.java index 80dfa40932f..3f2786b7231 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/TermsComponent.java +++ b/solr/core/src/java/org/apache/solr/handler/component/TermsComponent.java @@ -108,6 +108,16 @@ public class TermsComponent extends SearchComponent { rb.rsp.add("terms", termsResult); if (fields == null || fields.length==0) return; + + for (String field : fields) { + FieldType fieldType = rb.req.getSchema().getFieldTypeNoEx(field); + if (null != fieldType) { + if (fieldType.isPointField()) { + throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, + "The terms component does not support Points-based field " + field); + } + } + } boolean termStats = params.getBool(TermsParams.TERMS_STATS, false); diff --git a/solr/core/src/test/org/apache/solr/handler/component/DistributedTermsComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/DistributedTermsComponentTest.java index 6f719d2bd29..53ee9061e9e 100644 --- a/solr/core/src/test/org/apache/solr/handler/component/DistributedTermsComponentTest.java +++ b/solr/core/src/test/org/apache/solr/handler/component/DistributedTermsComponentTest.java @@ -26,7 +26,7 @@ import org.junit.Test; * * @since solr 1.5 */ -@SuppressPointFields(bugUrl="https://issues.apache.org/jira/browse/SOLR-10847") +@SuppressPointFields(bugUrl="https://issues.apache.org/jira/browse/SOLR-11173") public class DistributedTermsComponentTest extends BaseDistributedSearchTestCase { @Test diff --git a/solr/core/src/test/org/apache/solr/handler/component/TermsComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/TermsComponentTest.java index 2a8b653aeac..ac7cf2ac057 100644 --- a/solr/core/src/test/org/apache/solr/handler/component/TermsComponentTest.java +++ b/solr/core/src/test/org/apache/solr/handler/component/TermsComponentTest.java @@ -16,6 +16,7 @@ */ package org.apache.solr.handler.component; import org.apache.solr.SolrTestCaseJ4; +import org.apache.solr.common.SolrException; import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.params.TermsParams; import org.apache.solr.request.SolrQueryRequest; @@ -29,7 +30,7 @@ import java.util.regex.Pattern; * **/ // TermsComponent not currently supported for PointFields -@SolrTestCaseJ4.SuppressPointFields(bugUrl="https://issues.apache.org/jira/browse/SOLR-10847") +@SolrTestCaseJ4.SuppressPointFields(bugUrl="https://issues.apache.org/jira/browse/SOLR-11173") public class TermsComponentTest extends SolrTestCaseJ4 { @BeforeClass @@ -378,4 +379,31 @@ public class TermsComponentTest extends SolrTestCaseJ4 { "//lst[@name='standardfilt']/lst[@name='aaa']/long[@name='ttf'][.='1']"); } + @Test + public void testPointField() throws Exception { + assertU(adoc("id", "10000", "foo_pi", "1")); + assertU(commit()); + + try { + final SolrQueryRequest req = req( + "qt", "/terms", + "terms", "true", + "terms.fl", "foo_pi"); + Exception e = expectThrows(SolrException.class, () -> h.query(req)); + assertEquals(SolrException.ErrorCode.BAD_REQUEST.code, ((SolrException) e).code()); + assertTrue(e.getMessage().contains("The terms component does not support Points-based field foo_pi")); + + final SolrQueryRequest req2 = req( + "qt", "/terms", + "terms", "true", + "terms.fl", "foo_pi", + "terms.list", "1"); + e = expectThrows(SolrException.class, () -> h.query(req2)); + assertEquals(SolrException.ErrorCode.BAD_REQUEST.code, ((SolrException) e).code()); + assertTrue(e.getMessage().contains("The terms component does not support Points-based field foo_pi")); + } finally { + assertU(delI("10000")); + assertU(commit()); + } + } }