Apache Lucene open-source search software
SOLR-2669: Fix backwards validation logic in SchemaField.calcProps
Chris M. Hostetter7c1a58f72dce
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 0f47442b718..3cb6c0ceb59 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -288,6 +288,19 @@ Upgrading from Solr 3.3before the master. If the master were to be updated first, the oldersearchers would not be able to read the new index format.+* Previous versions of Solr silently allow and ignore some contradictory+ properties specified in schema.xml. For example:+ - indexed="false" omitNorms="false"+ - indexed="false" omitTermFreqAndPositions="false"+ Field property validation has now been fixed, to ensure that+ contradictions like these now generate error messages. If users+ have existing schemas that generate one of these new "conflicting+ 'false' field options for non-indexed field" error messages the+ conflicting "omit*" properties can safely be removed, or changed to+ "true" for consistent behavior with previous Solr versions. This+ situation has now been fixed to cause an error on startup when these+ contradictory options. See SOLR-2669.+New Features----------------------@@ -378,6 +391,8 @@ Bug Fixes"start" parameter was not honored and the documents returned were0 through start+offset. (Markus Jelsma, yonik)+* SOLR-2669: Fix backwards validation of field properties in+ SchemaField.calcProps (hossman)Other Changesdiff --git a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java b/solr/core/src/java/org/apache/solr/schema/IndexSchema.javaindex 89b958bbf3c..237bb463287 100644--- a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java+++ b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java@@ -577,7 +577,7 @@ public final class IndexSchema {} catch(Exception e) {// unexpected exception...SolrConfig.severeErrors.add( e );- throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Schema Parsing Failed",e,false);+ throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Schema Parsing Failed: " + e.getMessage(), e,false);}// create the field analyzersdiff --git a/solr/core/src/java/org/apache/solr/schema/SchemaField.java b/solr/core/src/java/org/apache/solr/schema/SchemaField.javaindex 86b102ba774..4d881d50627 100644--- a/solr/core/src/java/org/apache/solr/schema/SchemaField.java+++ b/solr/core/src/java/org/apache/solr/schema/SchemaField.java@@ -226,20 +226,27 @@ public final class SchemaField extends FieldProperties {}if (on(falseProps,INDEXED)) {- int pp = (INDEXED | OMIT_NORMS | OMIT_TF_POSITIONS | OMIT_POSITIONS+ int pp = (INDEXED| STORE_TERMVECTORS | STORE_TERMPOSITIONS | STORE_TERMOFFSETS| SORT_MISSING_FIRST | SORT_MISSING_LAST);if (on(pp,trueProps)) {- throw new RuntimeException("SchemaField: " + name + " conflicting indexed field options:" + props);+ throw new RuntimeException("SchemaField: " + name + " conflicting 'true' field options for non-indexed field:" + props);+ }+ p &= ~pp;+ }+ if (on(falseProps,INDEXED)) {+ int pp = (OMIT_NORMS | OMIT_TF_POSITIONS | OMIT_POSITIONS);+ if (on(pp,falseProps)) {+ throw new RuntimeException("SchemaField: " + name + " conflicting 'false' field options for non-indexed field:" + props);}p &= ~pp;}- if (on(falseProps,OMIT_TF_POSITIONS)) {+ if (on(trueProps,OMIT_TF_POSITIONS)) {int pp = (OMIT_POSITIONS | OMIT_TF_POSITIONS);- if (on(pp, trueProps)) {- throw new RuntimeException("SchemaField: " + name + " conflicting indexed field options:" + props);+ if (on(pp, falseProps)) {+ throw new RuntimeException("SchemaField: " + name + " conflicting tf and position field options:" + props);}p &= ~pp;}diff --git a/solr/core/src/test-files/solr/conf/bad-schema-not-indexed-but-norms.xml b/solr/core/src/test-files/solr/conf/bad-schema-not-indexed-but-norms.xmlnew file mode 100644index 00000000000..f7c4e9b2d80--- /dev/null+++ b/solr/core/src/test-files/solr/conf/bad-schema-not-indexed-but-norms.xml@@ -0,0 +1,40 @@+<?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-not-indexed-but-norms" version="1.0">+ <types>+ <fieldType name="string" class="solr.StrField"/>+ </types>++ <fields>+ <field name="id" type="string" indexed="true" stored="true" multiValued="false" required="false"/>++ <field name="signatureField" type="string" indexed="true" stored="false"/>++ <!-- BEGIN BAD STUFF -->+ <field name="bad_field" type="string" indexed="false" omitNorms="false" />+ <!-- END BAD STUFF -->++ <dynamicField name="*_sS" type="string" indexed="false" stored="true"/>++ </fields>++ <defaultSearchField>id</defaultSearchField>+ <uniqueKey>id</uniqueKey>++</schema>diff --git a/solr/core/src/test-files/solr/conf/bad-schema-not-indexed-but-pos.xml b/solr/core/src/test-files/solr/conf/bad-schema-not-indexed-but-pos.xmlnew file mode 100644index 00000000000..774d58755f4--- /dev/null+++ b/solr/core/src/test-files/solr/conf/bad-schema-not-indexed-but-pos.xml@@ -0,0 +1,40 @@+<?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-not-indexed-but-pos" version="1.0">+ <types>+ <fieldType name="string" class="solr.StrField"/>+ </types>++ <fields>+ <field name="id" type="string" indexed="true" stored="true" multiValued="false" required="false"/>++ <field name="signatureField" type="string" indexed="true" stored="false"/>++ <!-- BEGIN BAD STUFF -->+ <field name="bad_field" type="string" indexed="false" omitPositions="false" />+ <!-- END BAD STUFF -->++ <dynamicField name="*_sS" type="string" indexed="false" stored="true"/>++ </fields>++ <defaultSearchField>id</defaultSearchField>+ <uniqueKey>id</uniqueKey>++</schema>diff --git a/solr/core/src/test-files/solr/conf/bad-schema-not-indexed-but-tf.xml b/solr/core/src/test-files/solr/conf/bad-schema-not-indexed-but-tf.xmlnew file mode 100644index 00000000000..d153793830a--- /dev/null+++ b/solr/core/src/test-files/solr/conf/bad-schema-not-indexed-but-tf.xml@@ -0,0 +1,40 @@+<?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-not-indexed-but-tf" version="1.0">+ <types>+ <fieldType name="string" class="solr.StrField"/>+ </types>++ <fields>+ <field name="id" type="string" indexed="true" stored="true" multiValued="false" required="false"/>++ <field name="signatureField" type="string" indexed="true" stored="false"/>++ <!-- BEGIN BAD STUFF -->+ <field name="bad_field" type="string" indexed="false" omitTermFreqAndPositions="false" />+ <!-- END BAD STUFF -->++ <dynamicField name="*_sS" type="string" indexed="false" stored="true"/>++ </fields>++ <defaultSearchField>id</defaultSearchField>+ <uniqueKey>id</uniqueKey>++</schema>diff --git a/solr/core/src/test-files/solr/conf/bad-schema-omit-tf-but-not-pos.xml b/solr/core/src/test-files/solr/conf/bad-schema-omit-tf-but-not-pos.xmlnew file mode 100644index 00000000000..116f116a176--- /dev/null+++ b/solr/core/src/test-files/solr/conf/bad-schema-omit-tf-but-not-pos.xml@@ -0,0 +1,41 @@+<?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-omit-tf-but-not-pos" version="1.0">+ <types>+ <fieldType name="string" class="solr.StrField"/>+ </types>++ <fields>+ <field name="id" type="string" indexed="true" stored="true" multiValued="false" required="false"/>++ <field name="signatureField" type="string" indexed="true" stored="false"/>++ <!-- BEGIN BAD STUFF -->+ <field name="bad_field" type="string" indexed="true"+ omitTermFreqAndPositions="true" omitPositions="false" />+ <!-- END BAD STUFF -->++ <dynamicField name="*_sS" type="string" indexed="false" stored="true"/>++ </fields>++ <defaultSearchField>id</defaultSearchField>+ <uniqueKey>id</uniqueKey>++</schema>diff --git a/solr/core/src/test-files/solr/conf/schema.xml b/solr/core/src/test-files/solr/conf/schema.xmlindex 62c8051f182..c6c256f39f5 100644--- a/solr/core/src/test-files/solr/conf/schema.xml+++ b/solr/core/src/test-files/solr/conf/schema.xml@@ -481,6 +481,24 @@<field name="test_posofftv" type="text" termVectors="true"termPositions="true" termOffsets="true"/>+ <!-- test valid combinations of indexed settings,+ see also BadIndexSchemaTest -->+ <!-- 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"+ 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"+ omitPositions="true" />+ <!-- omitOmitTermFreqAndPositions=false and omitPositions=true are ok -->+ <field name="pint_tf_pos" type="pint" indexed="true"+ omitOmitTermFreqAndPositions="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"/>diff --git a/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java b/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.javaindex 0525f2ba6ff..59b6c7f3c77 100644--- a/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java+++ b/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java@@ -48,6 +48,14 @@ public class BadIndexSchemaTest extends SolrTestCaseJ4 {fail("Did not encounter any exception from: " + schema);}+ @Test+ public void testSevereErrorsForInvalidFieldOptions() throws Exception {+ doTest("bad-schema-not-indexed-but-norms.xml", "bad_field");+ doTest("bad-schema-not-indexed-but-tf.xml", "bad_field");+ doTest("bad-schema-not-indexed-but-pos.xml", "bad_field");+ doTest("bad-schema-omit-tf-but-not-pos.xml", "bad_field");+ }+@Testpublic void testSevereErrorsForDuplicateFields() throws Exception {doTest("bad-schema-dup-field.xml", "fAgain");