Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-4641: Schema should throw exceptoin on illegal field parameters

Robert Muirabea80640920
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 53bb4409aa5..d73c34a5a2b 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -118,6 +118,8 @@ Bug Fixes
* SOLR-4650: copyField doesn't work with source globs that don't match any
explicit or dynamic fields. This regression was introduced in Solr 4.2.
(Daniel Collins, Steve Rowe)
+
+* SOLR-4641: Schema now throws exception on illegal field parameters. (Robert Muir)
Optimizations
----------------------
diff --git a/solr/contrib/clustering/src/test-files/clustering/solr/collection1/conf/schema.xml b/solr/contrib/clustering/src/test-files/clustering/solr/collection1/conf/schema.xml
index 9afe1f086eb..1804e680bc8 100644
--- a/solr/contrib/clustering/src/test-files/clustering/solr/collection1/conf/schema.xml
+++ b/solr/contrib/clustering/src/test-files/clustering/solr/collection1/conf/schema.xml
@@ -265,9 +265,6 @@
type: mandatory - the name of a previously defined type from the <types> section
indexed: true if this field should be indexed (searchable or sortable)
stored: true if this field should be retrievable
- compressed: [false] if this field should be stored using gzip compression
- (this will only apply if the field type is compressable; among
- the standard field types, only TextField and StrField are)
multiValued: true if this field may contain multiple values per document
omitNorms: (expert) set to true to omit the norms associated with
this field (this disables length normalization and index-time
diff --git a/solr/contrib/dataimporthandler/src/test-files/dih/solr/collection1/conf/dataimport-solr_id-schema.xml b/solr/contrib/dataimporthandler/src/test-files/dih/solr/collection1/conf/dataimport-solr_id-schema.xml
index e789b05ec47..7bfd6c2e046 100644
--- a/solr/contrib/dataimporthandler/src/test-files/dih/solr/collection1/conf/dataimport-solr_id-schema.xml
+++ b/solr/contrib/dataimporthandler/src/test-files/dih/solr/collection1/conf/dataimport-solr_id-schema.xml
@@ -246,9 +246,6 @@
type: mandatory - the name of a previously defined type from the <types> section
indexed: true if this field should be indexed (searchable or sortable)
stored: true if this field should be retrievable
- compressed: [false] if this field should be stored using gzip compression
- (this will only apply if the field type is compressable; among
- the standard field types, only TextField and StrField are)
multiValued: true if this field may contain multiple values per document
omitNorms: (expert) set to true to omit the norms associated with
this field (this disables length normalization and index-time
diff --git a/solr/contrib/extraction/src/test-files/extraction/solr/collection1/conf/schema.xml b/solr/contrib/extraction/src/test-files/extraction/solr/collection1/conf/schema.xml
index 6bf238bcf90..a08d698d207 100644
--- a/solr/contrib/extraction/src/test-files/extraction/solr/collection1/conf/schema.xml
+++ b/solr/contrib/extraction/src/test-files/extraction/solr/collection1/conf/schema.xml
@@ -354,8 +354,8 @@
termPositions="true" termOffsets="true"/>
<!-- test highlit field settings -->
- <field name="test_hlt" type="highlittext" indexed="true" compressed="true"/>
- <field name="test_hlt_off" type="highlittext" indexed="true" compressed="false"/>
+ <field name="test_hlt" type="highlittext" indexed="true"/>
+ <field name="test_hlt_off" type="highlittext" indexed="true"/>
<!-- fields to test individual tokenizers and tokenfilters -->
<field name="teststop" type="teststop" indexed="true" stored="true"/>
diff --git a/solr/contrib/uima/src/test-files/uima/solr/collection1/conf/schema.xml b/solr/contrib/uima/src/test-files/uima/solr/collection1/conf/schema.xml
index db7c1900fb3..e2f761e3657 100644
--- a/solr/contrib/uima/src/test-files/uima/solr/collection1/conf/schema.xml
+++ b/solr/contrib/uima/src/test-files/uima/solr/collection1/conf/schema.xml
@@ -470,10 +470,7 @@
field type: mandatory - the name of a previously defined type from
the <types> section indexed: true if this field should be indexed
(searchable or sortable) stored: true if this field should be
- retrievable compressed: [false] if this field should be stored
- using gzip compression (this will only apply if the field type is
- compressable; among the standard field types, only TextField and
- StrField are) multiValued: true if this field may contain multiple
+ retrievable multiValued: true if this field may contain multiple
values per document omitNorms: (expert) set to true to omit the
norms associated with this field (this disables length
normalization and index-time boosting for the field, and saves
diff --git a/solr/contrib/uima/src/test-files/uima/uima-tokenizers-schema.xml b/solr/contrib/uima/src/test-files/uima/uima-tokenizers-schema.xml
index cd9a0bc3d87..37c8d98883e 100644
--- a/solr/contrib/uima/src/test-files/uima/uima-tokenizers-schema.xml
+++ b/solr/contrib/uima/src/test-files/uima/uima-tokenizers-schema.xml
@@ -466,10 +466,7 @@
field type: mandatory - the name of a previously defined type from
the <types> section indexed: true if this field should be indexed
(searchable or sortable) stored: true if this field should be
- retrievable compressed: [false] if this field should be stored
- using gzip compression (this will only apply if the field type is
- compressable; among the standard field types, only TextField and
- StrField are) multiValued: true if this field may contain multiple
+ retrievable multiValued: true if this field may contain multiple
values per document omitNorms: (expert) set to true to omit the
norms associated with this field (this disables length
normalization and index-time boosting for the field, and saves
diff --git a/solr/core/src/java/org/apache/solr/schema/FieldProperties.java b/solr/core/src/java/org/apache/solr/schema/FieldProperties.java
index 3a2b987b72c..2eedf05197d 100644
--- a/solr/core/src/java/org/apache/solr/schema/FieldProperties.java
+++ b/solr/core/src/java/org/apache/solr/schema/FieldProperties.java
@@ -64,7 +64,7 @@ public abstract class FieldProperties {
static final Map<String,Integer> propertyMap = new HashMap<String,Integer>();
static {
for (String prop : propertyNames) {
- propertyMap.put(prop, propertyNameToInt(prop));
+ propertyMap.put(prop, propertyNameToInt(prop, true));
}
}
@@ -74,13 +74,17 @@ public abstract class FieldProperties {
return propertyNames[ Integer.numberOfTrailingZeros(property) ];
}
- static int propertyNameToInt(String name) {
+ static int propertyNameToInt(String name, boolean failOnError) {
for (int i=0; i<propertyNames.length; i++) {
if (propertyNames[i].equals(name)) {
return 1 << i;
}
}
- return 0;
+ if (failOnError && !"default".equals(name)) {
+ throw new IllegalArgumentException("Invalid field property: " + name);
+ } else {
+ return 0;
+ }
}
@@ -105,13 +109,13 @@ public abstract class FieldProperties {
return (bitfield & props) == 0;
}
- static int parseProperties(Map<String,String> properties, boolean which) {
+ static int parseProperties(Map<String,String> properties, boolean which, boolean failOnError) {
int props = 0;
for (Map.Entry<String, String> entry : properties.entrySet()) {
String val = entry.getValue();
if(val == null) continue;
if (Boolean.parseBoolean(val) == which) {
- props |= propertyNameToInt(entry.getKey());
+ props |= propertyNameToInt(entry.getKey(), failOnError);
}
}
return props;
diff --git a/solr/core/src/java/org/apache/solr/schema/FieldType.java b/solr/core/src/java/org/apache/solr/schema/FieldType.java
index c0b8b341130..bc4095d50f5 100644
--- a/solr/core/src/java/org/apache/solr/schema/FieldType.java
+++ b/solr/core/src/java/org/apache/solr/schema/FieldType.java
@@ -153,8 +153,8 @@ public abstract class FieldType extends FieldProperties {
this.args = Collections.unmodifiableMap(args);
Map<String,String> initArgs = new HashMap<String,String>(args);
- trueProperties = FieldProperties.parseProperties(initArgs,true);
- falseProperties = FieldProperties.parseProperties(initArgs,false);
+ trueProperties = FieldProperties.parseProperties(initArgs,true,false);
+ falseProperties = FieldProperties.parseProperties(initArgs,false,false);
properties &= ~falseProperties;
properties |= trueProperties;
diff --git a/solr/core/src/java/org/apache/solr/schema/SchemaField.java b/solr/core/src/java/org/apache/solr/schema/SchemaField.java
index 8d6c42105de..1b402075e45 100644
--- a/solr/core/src/java/org/apache/solr/schema/SchemaField.java
+++ b/solr/core/src/java/org/apache/solr/schema/SchemaField.java
@@ -221,8 +221,8 @@ public final class SchemaField extends FieldProperties {
}
static int calcProps(String name, FieldType ft, Map<String, String> props) {
- int trueProps = parseProperties(props,true);
- int falseProps = parseProperties(props,false);
+ int trueProps = parseProperties(props,true,true);
+ int falseProps = parseProperties(props,false,true);
int p = ft.properties;
diff --git a/solr/core/src/test-files/solr/collection1/conf/bad-schema-bogus-field-parameters.xml b/solr/core/src/test-files/solr/collection1/conf/bad-schema-bogus-field-parameters.xml
new file mode 100644
index 00000000000..3575c438c72
--- /dev/null
+++ b/solr/core/src/test-files/solr/collection1/conf/bad-schema-bogus-field-parameters.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" ?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<schema name="bad-schema-bogus-field-parameters" version="1.5">
+ <types>
+ <fieldType name="binary" class="solr.BinaryField" />
+ </types>
+
+
+ <fields>
+ <field name="id" type="binary" someBogusParam="true"/>
+ </fields>
+
+</schema>
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-copyfield-test.xml b/solr/core/src/test-files/solr/collection1/conf/schema-copyfield-test.xml
index 6c45681d215..68fbb219894 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema-copyfield-test.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema-copyfield-test.xml
@@ -346,8 +346,8 @@
termPositions="true" termOffsets="true"/>
<!-- test highlit field settings -->
- <field name="test_hlt" type="highlittext" indexed="true" compressed="true"/>
- <field name="test_hlt_off" type="highlittext" indexed="true" compressed="false"/>
+ <field name="test_hlt" type="highlittext" indexed="true"/>
+ <field name="test_hlt_off" type="highlittext" indexed="true"/>
<!-- fields to test individual tokenizers and tokenfilters -->
<field name="teststop" type="teststop" indexed="true" stored="true"/>
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-required-fields.xml b/solr/core/src/test-files/solr/collection1/conf/schema-required-fields.xml
index 019643f6b09..38b52c56931 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema-required-fields.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema-required-fields.xml
@@ -337,8 +337,8 @@
termPositions="true" termOffsets="true"/>
<!-- test highlit field settings -->
- <field name="test_hlt" type="highlittext" indexed="true" compressed="true"/>
- <field name="test_hlt_off" type="highlittext" indexed="true" compressed="false"/>
+ <field name="test_hlt" type="highlittext" indexed="true"/>
+ <field name="test_hlt_off" type="highlittext" indexed="true"/>
<!-- fields to test individual tokenizers and tokenfilters -->
<field name="teststop" type="teststop" indexed="true" stored="true"/>
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-rest.xml b/solr/core/src/test-files/solr/collection1/conf/schema-rest.xml
index 96e3645bcec..f372102a2d5 100755
--- a/solr/core/src/test-files/solr/collection1/conf/schema-rest.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema-rest.xml
@@ -469,8 +469,8 @@
termPositions="true" termOffsets="true"/>
<!-- test highlit field settings -->
- <field name="test_hlt" type="highlittext" indexed="true" compressed="true"/>
- <field name="test_hlt_off" type="highlittext" indexed="true" compressed="false"/>
+ <field name="test_hlt" type="highlittext" indexed="true"/>
+ <field name="test_hlt_off" type="highlittext" indexed="true"/>
<!-- fields to test individual tokenizers and tokenfilters -->
<field name="teststop" type="teststop" indexed="true" stored="true"/>
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-trie.xml b/solr/core/src/test-files/solr/collection1/conf/schema-trie.xml
index 6a8bc6e6208..85ad7b7e263 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema-trie.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema-trie.xml
@@ -258,9 +258,6 @@
type: mandatory - the name of a previously defined type from the <types> section
indexed: true if this field should be indexed (searchable or sortable)
stored: true if this field should be retrievable
- compressed: [false] if this field should be stored using gzip compression
- (this will only apply if the field type is compressable; among
- the standard field types, only TextField and StrField are)
multiValued: true if this field may contain multiple values per document
omitNorms: (expert) set to true to omit the norms associated with
this field (this disables length normalization and index-time
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema.xml b/solr/core/src/test-files/solr/collection1/conf/schema.xml
index 884bf2abd9a..fca84bf6996 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema.xml
@@ -506,22 +506,22 @@
<!-- indexed=false should not prevent omit___=true -->
<field name="pint_i_norm" type="pint" omitNorms="true"
indexed="false" />
- <field name="pint_i_tf" type="pint" omitOmitTermFreqAndPositions="true"
+ <field name="pint_i_tf" type="pint" omitTermFreqAndPositions="true"
indexed="false" />
<field name="pint_i_pos" type="pint" omitPositions="true"
indexed="false" />
<field name="pint_i_all" type="pint"
indexed="false"
omitNorms="true"
- omitOmitTermFreqAndPositions="true"
+ omitTermFreqAndPositions="true"
omitPositions="true" />
- <!-- omitOmitTermFreqAndPositions=false and omitPositions=true are ok -->
+ <!-- omitTermFreqAndPositions=false and omitPositions=true are ok -->
<field name="pint_tf_pos" type="pint" indexed="true"
- omitOmitTermFreqAndPositions="false" omitPositions="true" />
+ omitTermFreqAndPositions="false" omitPositions="true" />
<!-- test highlit field settings -->
- <field name="test_hlt" type="highlittext" indexed="true" compressed="true"/>
- <field name="test_hlt_off" type="highlittext" indexed="true" compressed="false"/>
+ <field name="test_hlt" type="highlittext" indexed="true"/>
+ <field name="test_hlt_off" type="highlittext" indexed="true"/>
<!-- fields to test individual tokenizers and tokenfilters -->
<field name="teststop" type="teststop" indexed="true" stored="true"/>
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 985e8ca77dd..5c2e28171d5 100755
--- a/solr/core/src/test-files/solr/collection1/conf/schema11.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema11.xml
@@ -296,9 +296,6 @@ valued. -->
type: mandatory - the name of a previously defined type from the <types> section
indexed: true if this field should be indexed (searchable or sortable)
stored: true if this field should be retrievable
- compressed: [false] if this field should be stored using gzip compression
- (this will only apply if the field type is compressable; among
- the standard field types, only TextField and StrField are)
multiValued: true if this field may contain multiple values per document
omitNorms: (expert) set to true to omit the norms associated with
this field (this disables length normalization and index-time
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema12.xml b/solr/core/src/test-files/solr/collection1/conf/schema12.xml
index c1aa3e618ec..fb28710d77e 100755
--- a/solr/core/src/test-files/solr/collection1/conf/schema12.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema12.xml
@@ -472,8 +472,8 @@
termPositions="true" termOffsets="true"/>
<!-- test highlit field settings -->
- <field name="test_hlt" type="highlittext" indexed="true" compressed="true"/>
- <field name="test_hlt_off" type="highlittext" indexed="true" compressed="false"/>
+ <field name="test_hlt" type="highlittext" indexed="true"/>
+ <field name="test_hlt_off" type="highlittext" indexed="true"/>
<!-- fields to test individual tokenizers and tokenfilters -->
<field name="teststop" type="teststop" indexed="true" stored="true"/>
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema15.xml b/solr/core/src/test-files/solr/collection1/conf/schema15.xml
index 50bb210254c..0b1cefc1cdc 100755
--- a/solr/core/src/test-files/solr/collection1/conf/schema15.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema15.xml
@@ -470,8 +470,8 @@
termPositions="true" termOffsets="true"/>
<!-- test highlit field settings -->
- <field name="test_hlt" type="highlittext" indexed="true" compressed="true"/>
- <field name="test_hlt_off" type="highlittext" indexed="true" compressed="false"/>
+ <field name="test_hlt" type="highlittext" indexed="true"/>
+ <field name="test_hlt_off" type="highlittext" indexed="true"/>
<!-- fields to test individual tokenizers and tokenfilters -->
<field name="teststop" type="teststop" indexed="true" stored="true"/>
diff --git a/solr/core/src/test-files/solr/collection1/conf/schemasurround.xml b/solr/core/src/test-files/solr/collection1/conf/schemasurround.xml
index 823e313c1eb..d6f4664076a 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schemasurround.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schemasurround.xml
@@ -487,8 +487,8 @@
termPositions="true" termOffsets="true"/>
<!-- test highlit field settings -->
- <field name="test_hlt" type="highlittext" indexed="true" compressed="true"/>
- <field name="test_hlt_off" type="highlittext" indexed="true" compressed="false"/>
+ <field name="test_hlt" type="highlittext" indexed="true"/>
+ <field name="test_hlt_off" type="highlittext" indexed="true"/>
<!-- fields to test individual tokenizers and tokenfilters -->
<field name="teststop" type="teststop" indexed="true" stored="true"/>
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 d631697e5b3..d390a4cb771 100644
--- a/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java
+++ b/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java
@@ -23,7 +23,7 @@ public class BadIndexSchemaTest extends AbstractBadConfigTestBase {
private void doTest(final String schema, final String errString)
throws Exception {
- assertConfigs("solrconfig.xml", schema, errString);
+ assertConfigs("solrconfig-basic.xml", schema, errString);
}
public void testSevereErrorsForInvalidFieldOptions() throws Exception {
@@ -110,5 +110,9 @@ public class BadIndexSchemaTest extends AbstractBadConfigTestBase {
doTest("bad-schema-sweetspot-partial-norms.xml",
"Overriding default lengthNorm");
}
+
+ public void testBogusParameters() throws Exception {
+ doTest("bad-schema-bogus-field-parameters.xml", "Invalid field property");
+ }
}
diff --git a/solr/example/example-DIH/solr/db/conf/schema.xml b/solr/example/example-DIH/solr/db/conf/schema.xml
index 45d6662201b..50ee5e015ba 100644
--- a/solr/example/example-DIH/solr/db/conf/schema.xml
+++ b/solr/example/example-DIH/solr/db/conf/schema.xml
@@ -246,9 +246,6 @@
type: mandatory - the name of a previously defined type from the <types> section
indexed: true if this field should be indexed (searchable or sortable)
stored: true if this field should be retrievable
- compressed: [false] if this field should be stored using gzip compression
- (this will only apply if the field type is compressable; among
- the standard field types, only TextField and StrField are)
multiValued: true if this field may contain multiple values per document
omitNorms: (expert) set to true to omit the norms associated with
this field (this disables length normalization and index-time
diff --git a/solr/example/example-DIH/solr/mail/conf/schema.xml b/solr/example/example-DIH/solr/mail/conf/schema.xml
index 663fc579111..c7cddbb93db 100644
--- a/solr/example/example-DIH/solr/mail/conf/schema.xml
+++ b/solr/example/example-DIH/solr/mail/conf/schema.xml
@@ -324,9 +324,6 @@
type: mandatory - the name of a previously defined type from the <types> section
indexed: true if this field should be indexed (searchable or sortable)
stored: true if this field should be retrievable
- compressed: [false] if this field should be stored using gzip compression
- (this will only apply if the field type is compressable; among
- the standard field types, only TextField and StrField are)
multiValued: true if this field may contain multiple values per document
omitNorms: (expert) set to true to omit the norms associated with
this field (this disables length normalization and index-time
diff --git a/solr/example/example-DIH/solr/rss/conf/schema.xml b/solr/example/example-DIH/solr/rss/conf/schema.xml
index 38488cb8bb8..dbaa865fb12 100644
--- a/solr/example/example-DIH/solr/rss/conf/schema.xml
+++ b/solr/example/example-DIH/solr/rss/conf/schema.xml
@@ -273,9 +273,6 @@
type: mandatory - the name of a previously defined type from the <types> section
indexed: true if this field should be indexed (searchable or sortable)
stored: true if this field should be retrievable
- compressed: [false] if this field should be stored using gzip compression
- (this will only apply if the field type is compressable; among
- the standard field types, only TextField and StrField are)
multiValued: true if this field may contain multiple values per document
omitNorms: (expert) set to true to omit the norms associated with
this field (this disables length normalization and index-time
diff --git a/solr/example/example-DIH/solr/solr/conf/schema.xml b/solr/example/example-DIH/solr/solr/conf/schema.xml
index c78d417277c..299fd379b6f 100644
--- a/solr/example/example-DIH/solr/solr/conf/schema.xml
+++ b/solr/example/example-DIH/solr/solr/conf/schema.xml
@@ -246,9 +246,6 @@
type: mandatory - the name of a previously defined type from the <types> section
indexed: true if this field should be indexed (searchable or sortable)
stored: true if this field should be retrievable
- compressed: [false] if this field should be stored using gzip compression
- (this will only apply if the field type is compressable; among
- the standard field types, only TextField and StrField are)
multiValued: true if this field may contain multiple values per document
omitNorms: (expert) set to true to omit the norms associated with
this field (this disables length normalization and index-time