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 5ba98a4d751..c4dbf19f229 100755
--- a/solr/core/src/java/org/apache/solr/schema/ExternalFileField.java
+++ b/solr/core/src/java/org/apache/solr/schema/ExternalFileField.java
@@ -34,7 +34,9 @@ import java.io.IOException;
*
It's OK to have some documents without a keyField in the file (defVal is used as the default)
* It's OK for a keyField value to point to multiple documents (no uniqueness requirement)
*
- * valType
is a reference to another fieldType to define the value type of this field (must currently be FloatField (float))
+ * valType
is a reference to another fieldType to define the value type of this field
+ * (must currently be TrieFloatField or FloatField (valType="pfloat|float|tfloat") if used).
+ * This parameter has never been implemented. As of Solr 3.6/4.0 it is optional and can be omitted.
*
* The format of the external file is simply newline separated keyFieldValue=floatValue.
*
Example:
@@ -60,18 +62,21 @@ public class ExternalFileField extends FieldType {
private float defVal;
@Override
- protected void init(IndexSchema schema, Map args) {
+ protected void init(IndexSchema schema, Map args) {
restrictProps(SORT_MISSING_FIRST | SORT_MISSING_LAST);
- String ftypeS = getArg("valType", args);
- if (ftypeS!=null) {
+ // valType has never been used for anything except to throw an error, so make it optional since the
+ // code (see getValueSource) gives you a FileFloatSource.
+ String ftypeS = args.remove("valType");
+ if (ftypeS != null) {
ftype = schema.getFieldTypes().get(ftypeS);
- if (ftype==null || !(ftype instanceof FloatField)) {
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Only float (FloatField) is currently supported as external field type. got " + ftypeS);
+ if (ftype != null && !(ftype instanceof FloatField) && !(ftype instanceof TrieFloatField)) {
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
+ "Only float and pfloat (Trie|Float)Field are currently supported as external field type. Got " + ftypeS);
}
- }
+ }
keyFieldName = args.remove("keyField");
String defValS = args.remove("defVal");
- defVal = defValS==null ? 0 : Float.parseFloat(defValS);
+ defVal = defValS == null ? 0 : Float.parseFloat(defValS);
this.schema = schema;
}
diff --git a/solr/core/src/test-files/solr/conf/bad-schema-external-filefield.xml b/solr/core/src/test-files/solr/conf/bad-schema-external-filefield.xml
new file mode 100644
index 00000000000..e7874c88d25
--- /dev/null
+++ b/solr/core/src/test-files/solr/conf/bad-schema-external-filefield.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/solr/core/src/test-files/solr/conf/schema11.xml b/solr/core/src/test-files/solr/conf/schema11.xml
index 02cc2b51dc2..c4c932b8c5b 100755
--- a/solr/core/src/test-files/solr/conf/schema11.xml
+++ b/solr/core/src/test-files/solr/conf/schema11.xml
@@ -267,6 +267,24 @@
valued. -->
+
+
+
+
+
+
+
+
+
+
diff --git a/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java b/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java
index 59b6c7f3c77..0cbd1748b39 100644
--- a/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java
+++ b/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java
@@ -35,8 +35,10 @@ public class BadIndexSchemaTest extends SolrTestCaseJ4 {
try {
initCore( "solrconfig.xml", schema );
} catch (SolrException e) {
- // short circut out if we found what we expected
+ // short circuit out if we found what we expected
if (-1 != e.getMessage().indexOf(errString)) return;
+ // Test the cause too in case the expected error is wrapped
+ if (-1 != e.getCause().getMessage().indexOf(errString)) return;
// otherwise, rethrow it, possibly completley unrelated
throw new SolrException
@@ -44,6 +46,7 @@ public class BadIndexSchemaTest extends SolrTestCaseJ4 {
"Unexpected error, expected error matching: " + errString, e);
} finally {
SolrConfig.severeErrors.clear();
+ deleteCore();
}
fail("Did not encounter any exception from: " + schema);
}
@@ -75,4 +78,10 @@ public class BadIndexSchemaTest extends SolrTestCaseJ4 {
public void testSevereErrorsForUnexpectedAnalyzer() throws Exception {
doTest("bad-schema-nontext-analyzer.xml", "StrField (bad_type)");
}
+
+ @Test
+ public void testBadExternalFileField() throws Exception {
+ doTest("bad-schema-external-filefield.xml",
+ "Only float and pfloat");
+ }
}