From b79c932a9f924f158f21bb23019685fec602d75e Mon Sep 17 00:00:00 2001 From: Steve Rowe Date: Thu, 27 Jul 2017 22:17:06 -0400 Subject: [PATCH] SOLR-10846: ExternalFileField/FloatFieldSource should throw a clear exception on initialization with a Points-based keyField, which is not supported --- solr/CHANGES.txt | 3 ++ .../apache/solr/schema/ExternalFileField.java | 6 +++ .../solr/collection1/conf/bad-schema-eff.xml | 44 +++++++++++++++++++ .../solr/collection1/conf/schema11.xml | 5 ++- .../schema/ExternalFileFieldSortTest.java | 21 +++++---- .../search/function/TestFunctionQuery.java | 5 +-- 6 files changed, 71 insertions(+), 13 deletions(-) create mode 100644 solr/core/src/test-files/solr/collection1/conf/bad-schema-eff.xml diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 0f437a9ea25..79f679784e4 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -569,6 +569,9 @@ Other Changes * SOLR-10926: Increase the odds of randomly choosing point fields in our SolrTestCaseJ4 numeric type randomization. (hossman, Steve Rowe) + +* SOLR-10846: ExternalFileField/FloatFieldSource should throw a clear exception on initialization with + a Points-based keyField, which is not supported. (hossman, Steve Rowe) ================== 6.7.0 ================== diff --git a/solr/core/src/java/org/apache/solr/schema/ExternalFileField.java b/solr/core/src/java/org/apache/solr/schema/ExternalFileField.java index da4b4db1225..db2d11b8433 100644 --- a/solr/core/src/java/org/apache/solr/schema/ExternalFileField.java +++ b/solr/core/src/java/org/apache/solr/schema/ExternalFileField.java @@ -22,6 +22,7 @@ import java.util.Map; import org.apache.lucene.index.IndexableField; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.search.SortField; +import org.apache.solr.common.SolrException; import org.apache.solr.response.TextResponseWriter; import org.apache.solr.search.QParser; import org.apache.solr.search.function.FileFloatSource; @@ -122,5 +123,10 @@ public class ExternalFileField extends FieldType implements SchemaAware { @Override public void inform(IndexSchema schema) { this.schema = schema; + + if (keyFieldName != null && schema.getFieldType(keyFieldName).isPointField()) { + throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, + "keyField '" + keyFieldName + "' has a Point field type, which is not supported."); + } } } diff --git a/solr/core/src/test-files/solr/collection1/conf/bad-schema-eff.xml b/solr/core/src/test-files/solr/collection1/conf/bad-schema-eff.xml new file mode 100644 index 00000000000..da662819f77 --- /dev/null +++ b/solr/core/src/test-files/solr/collection1/conf/bad-schema-eff.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + id + + + + + + + + + + + + + + diff --git a/solr/core/src/test-files/solr/collection1/conf/schema11.xml b/solr/core/src/test-files/solr/collection1/conf/schema11.xml index 674c25f8514..8b317b046f1 100644 --- a/solr/core/src/test-files/solr/collection1/conf/schema11.xml +++ b/solr/core/src/test-files/solr/collection1/conf/schema11.xml @@ -276,7 +276,10 @@ valued. --> - + + + diff --git a/solr/core/src/test/org/apache/solr/schema/ExternalFileFieldSortTest.java b/solr/core/src/test/org/apache/solr/schema/ExternalFileFieldSortTest.java index 1438cac1873..632b4137250 100644 --- a/solr/core/src/test/org/apache/solr/schema/ExternalFileFieldSortTest.java +++ b/solr/core/src/test/org/apache/solr/schema/ExternalFileFieldSortTest.java @@ -18,7 +18,7 @@ package org.apache.solr.schema; import org.apache.commons.io.FileUtils; import org.apache.solr.SolrTestCaseJ4; -import org.junit.BeforeClass; +import org.apache.solr.common.SolrException; import org.junit.Test; import java.io.File; @@ -26,12 +26,6 @@ import java.io.IOException; public class ExternalFileFieldSortTest extends SolrTestCaseJ4 { - @BeforeClass - public static void beforeTests() throws Exception { - initCore("solrconfig-basic.xml", "schema-eff.xml"); - updateExternalFile(); - } - static void updateExternalFile() throws IOException { final String testHome = SolrTestCaseJ4.getFile("solr/collection1").getParent(); String filename = "external_eff"; @@ -48,7 +42,10 @@ public class ExternalFileFieldSortTest extends SolrTestCaseJ4 { } @Test - public void testSort() { + public void testSort() throws Exception { + initCore("solrconfig-basic.xml", "schema-eff.xml"); + updateExternalFile(); + addDocuments(); assertQ("query", req("q", "*:*", "sort", "eff asc"), @@ -56,4 +53,12 @@ public class ExternalFileFieldSortTest extends SolrTestCaseJ4 { "//result/doc[position()=2]/str[.='1']", "//result/doc[position()=10]/str[.='8']"); } + + @Test + public void testPointKeyFieldType() throws Exception { + // This one should fail though, no "node" parameter specified + SolrException e = expectThrows(SolrException.class, + () -> initCore("solrconfig-basic.xml", "bad-schema-eff.xml")); + assertTrue(e.getMessage().contains("has a Point field type, which is not supported.")); + } } diff --git a/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java b/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java index 4cee94b86bb..afc8a0dc5a0 100644 --- a/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java +++ b/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java @@ -293,11 +293,8 @@ public class TestFunctionQuery extends SolrTestCaseJ4 { @Test public void testExternalFileFieldNumericKey() throws Exception { - assumeFalse("SOLR-10846: ExternalFileField/FileFloatSource throws NPE if keyField is Points based", - Boolean.getBoolean(NUMERIC_POINTS_SYSPROP)); - final String extField = "eff_trie"; - final String keyField = "eff_ti"; + final String keyField = "eff_tint"; assertU(adoc("id", "991", keyField, "91")); assertU(adoc("id", "992", keyField, "92")); assertU(adoc("id", "993", keyField, "93"));