diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 0f47442b718..3cb6c0ceb59 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -288,6 +288,19 @@ Upgrading from Solr 3.3 before the master. If the master were to be updated first, the older searchers 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 were 0 through start+offset. (Markus Jelsma, yonik) +* SOLR-2669: Fix backwards validation of field properties in + SchemaField.calcProps (hossman) Other Changes diff --git a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java index 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 analyzers 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 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.xml new file mode 100644 index 00000000000..f7c4e9b2d80 --- /dev/null +++ b/solr/core/src/test-files/solr/conf/bad-schema-not-indexed-but-norms.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + id + id + + 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.xml new file mode 100644 index 00000000000..774d58755f4 --- /dev/null +++ b/solr/core/src/test-files/solr/conf/bad-schema-not-indexed-but-pos.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + id + id + + 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.xml new file mode 100644 index 00000000000..d153793830a --- /dev/null +++ b/solr/core/src/test-files/solr/conf/bad-schema-not-indexed-but-tf.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + id + id + + 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.xml new file mode 100644 index 00000000000..116f116a176 --- /dev/null +++ b/solr/core/src/test-files/solr/conf/bad-schema-omit-tf-but-not-pos.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + id + id + + diff --git a/solr/core/src/test-files/solr/conf/schema.xml b/solr/core/src/test-files/solr/conf/schema.xml index 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 @@ + + + + + + + + + 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 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"); + } + @Test public void testSevereErrorsForDuplicateFields() throws Exception { doTest("bad-schema-dup-field.xml", "fAgain");