Apache Lucene open-source search software
SOLR-2890: Fixed a bug that prevented omitNorms and omitTermFreqAndPositions options from being respected in some <fieldType/> declarations
Chris M. Hostetterb229140e87fc
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 0811cd7139d..93a5e336006 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -269,6 +269,9 @@ Bug Fixesyou are replicating.(Mark Miller, Markus Jelsma)+* SOLR-2890: Fixed a bug that prevented omitNorms and omitTermFreqAndPositions+ options from being respected in some <fieldType/> declarations (hossman)+Other Changes----------------------diff --git a/solr/core/src/java/org/apache/solr/schema/FieldType.java b/solr/core/src/java/org/apache/solr/schema/FieldType.javaindex 0fb96a4fac5..9ba293c4a21 100644--- a/solr/core/src/java/org/apache/solr/schema/FieldType.java+++ b/solr/core/src/java/org/apache/solr/schema/FieldType.java@@ -86,7 +86,7 @@ public abstract class FieldType extends FieldProperties {public boolean isMultiValued() {return (properties & MULTIVALUED) != 0;}-+/** Check if a property is set */protected boolean hasProperty( int p ) {return (properties & p) != 0;diff --git a/solr/core/src/java/org/apache/solr/schema/PrimitiveFieldType.java b/solr/core/src/java/org/apache/solr/schema/PrimitiveFieldType.javaindex 7fe4c052c2f..a6767e7727a 100644--- a/solr/core/src/java/org/apache/solr/schema/PrimitiveFieldType.java+++ b/solr/core/src/java/org/apache/solr/schema/PrimitiveFieldType.java@@ -28,7 +28,9 @@ public abstract class PrimitiveFieldType extends FieldType {@Overrideprotected void init(IndexSchema schema, Map<String,String> args) {super.init(schema, args);- if(schema.getVersion() > 1.4) {+ if(schema.getVersion() > 1.4F &&+ // only override if it's not explicitly false+ 0 == (falseProperties & OMIT_NORMS)) {properties |= OMIT_NORMS;}}diff --git a/solr/core/src/java/org/apache/solr/schema/TextField.java b/solr/core/src/java/org/apache/solr/schema/TextField.javaindex 4529c41a2b6..39e786bbf80 100644--- a/solr/core/src/java/org/apache/solr/schema/TextField.java+++ b/solr/core/src/java/org/apache/solr/schema/TextField.java@@ -62,8 +62,12 @@ public class TextField extends FieldType {@Overrideprotected void init(IndexSchema schema, Map<String,String> args) {properties |= TOKENIZED;- if (schema.getVersion()> 1.1f) properties &= ~OMIT_TF_POSITIONS;- if (schema.getVersion() > 1.3f) {+ if (schema.getVersion() > 1.1F &&+ // only override if it's not explicitly true+ 0 == (trueProperties & OMIT_TF_POSITIONS)) {+ properties &= ~OMIT_TF_POSITIONS;+ }+ if (schema.getVersion() > 1.3F) {autoGeneratePhraseQueries = false;} else {autoGeneratePhraseQueries = true;diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-behavior.xml b/solr/core/src/test-files/solr/collection1/conf/schema-behavior.xmlnew file mode 100644index 00000000000..20b5a3533b9--- /dev/null+++ b/solr/core/src/test-files/solr/collection1/conf/schema-behavior.xml@@ -0,0 +1,121 @@+<?xml version="1.0" encoding="UTF-8" ?>+<!--+ 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.+-->++<!-- this schema file is used by SchemaVersionSpecificBehaviorTest with the+ env variable set to various values to test that the appropriate default+ behaviors are obeyed.+ -->+<schema name="version-behavior" version="${solr.schema.test.ver}">++ <types>+ <!-- all behavior is default -->+ <fieldType name="text" class="solr.TextField"/>+ <fieldType name="bool" class="solr.BoolField"/>+ <fieldType name="str" class="solr.StrField"/>++ <!-- explicit props on type -->+ <fieldType name="multi_f" class="solr.StrField" multiValued="false"/>+ <fieldType name="multi_t" class="solr.StrField" multiValued="true"/>++ <fieldType name="strnorm_f" class="solr.StrField" omitNorms="false"/>+ <fieldType name="strnorm_t" class="solr.StrField" omitNorms="true"/>+ <fieldType name="txtnorm_f" class="solr.TextField" omitNorms="false"/>+ <fieldType name="txtnorm_t" class="solr.TextField" omitNorms="true"/>++ <fieldType name="strTfP_f" class="solr.StrField" omitTermFreqAndPositions="false"/>+ <fieldType name="strTfP_t" class="solr.StrField" omitTermFreqAndPositions="true"/>+ <fieldType name="txtTfP_f" class="solr.TextField" omitTermFreqAndPositions="false"/>+ <fieldType name="txtTfP_t" class="solr.TextField" omitTermFreqAndPositions="true"/>++ <fieldType name="txt_phrase_f" class="solr.TextField"+ autoGeneratePhraseQueries="false"/>+ <fieldType name="txt_phrase_t" class="solr.TextField"+ autoGeneratePhraseQueries="true" />++ </types>+ <fields>++ <!-- all behavior is default -->++ <field name="text" type="text" />+ <field name="bool" type="bool" />+ <field name="str" type="str" />++ <dynamicField name="*_dyn_text" type="text" />+ <dynamicField name="*_dyn_bool" type="bool" />+ <dynamicField name="*_dyn_str" type="str" />++ <!-- explicit props on type -->+ <field name="ft_multi_f" type="multi_f" />+ <field name="ft_multi_t" type="multi_t" />+ <dynamicField name="*_dyn_str_ft_multi_f" type="multi_f" />+ <dynamicField name="*_dyn_str_ft_multi_t" type="multi_t" />++ <field name="ft_strnorm_f" type="strnorm_f" />+ <field name="ft_strnorm_t" type="strnorm_t" />+ <dynamicField name="*_dyn_ft_strnorm_f" type="strnorm_f" />+ <dynamicField name="*_dyn_ft_strnorm_t" type="strnorm_t" />++ <field name="ft_txtnorm_f" type="txtnorm_f" />+ <field name="ft_txtnorm_t" type="txtnorm_t" />+ <dynamicField name="*_dyn_ft_txtnorm_f" type="txtnorm_f" />+ <dynamicField name="*_dyn_ft_txtnorm_t" type="txtnorm_t" />++ <field name="ft_strTfP_f" type="strTfP_f" />+ <field name="ft_strTfP_t" type="strTfP_t" />+ <dynamicField name="*_dyn_ft_strTfP_f" type="strTfP_f" />+ <dynamicField name="*_dyn_ft_strTfP_t" type="strTfP_t" />++ <field name="ft_txtTfP_f" type="txtTfP_f" />+ <field name="ft_txtTfP_t" type="txtTfP_t" />+ <dynamicField name="*_dyn_ft_txtTfP_f" type="txtTfP_f" />+ <dynamicField name="*_dyn_ft_txtTfP_t" type="txtTfP_t" />++ <field name="ft_txt_phrase_f" type="txt_phrase_f" />+ <field name="ft_txt_phrase_t" type="txt_phrase_t" />+ <dynamicField name="*_dyn_ft_txt_phrase_f" type="txt_phrase_f" />+ <dynamicField name="*_dyn_ft_txt_phrase_t" type="txt_phrase_t" />++ <!-- explicit props on field -->+ <field name="multi_f" type="str" multiValued="false" />+ <field name="multi_t" type="str" multiValued="true" />+ <dynamicField name="*_dyn_str_multi_f" type="str" multiValued="false" />+ <dynamicField name="*_dyn_str_multi_t" type="str" multiValued="true" />++ <field name="strnorm_f" type="str" omitNorms="false" />+ <field name="strnorm_t" type="str" omitNorms="true" />+ <dynamicField name="*_dyn_strnorm_f" type="str" omitNorms="false" />+ <dynamicField name="*_dyn_strnorm_t" type="str" omitNorms="true" />++ <field name="txtnorm_f" type="text" omitNorms="false" />+ <field name="txtnorm_t" type="text" omitNorms="true" />+ <dynamicField name="*_dyn_txtnorm_f" type="text" omitNorms="false" />+ <dynamicField name="*_dyn_txtnorm_t" type="text" omitNorms="true" />++ <field name="strTfP_f" type="str" omitTermFreqAndPositions="false" />+ <field name="strTfP_t" type="str" omitTermFreqAndPositions="true" />+ <dynamicField name="*_dyn_strTfP_f" type="str" omitTermFreqAndPositions="false" />+ <dynamicField name="*_dyn_strTfP_t" type="str" omitTermFreqAndPositions="true" />++ <field name="txtTfP_f" type="text" omitTermFreqAndPositions="false" />+ <field name="txtTfP_t" type="text" omitTermFreqAndPositions="true" />+ <dynamicField name="*_dyn_txtTfP_f" type="text" omitTermFreqAndPositions="false" />+ <dynamicField name="*_dyn_txtTfP_t" type="text" omitTermFreqAndPositions="true" />++ </fields>+</schema>diff --git a/solr/core/src/test/org/apache/solr/schema/SchemaVersionSpecificBehaviorTest.java b/solr/core/src/test/org/apache/solr/schema/SchemaVersionSpecificBehaviorTest.javanew file mode 100644index 00000000000..da64cb33661--- /dev/null+++ b/solr/core/src/test/org/apache/solr/schema/SchemaVersionSpecificBehaviorTest.java@@ -0,0 +1,202 @@+/*+ * 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.+ */++package org.apache.solr.schema;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.core.SolrCore;+import org.apache.solr.schema.IndexSchema;+++import java.util.HashMap;+import java.util.Map;+++public class SchemaVersionSpecificBehaviorTest extends SolrTestCaseJ4 {++ public void testVersionBehavior() throws Exception {+ for (float v : new float[] { 1.0F, 1.1F, 1.2F, 1.3F, 1.4F, 1.5F }) {+ try {+ final IndexSchema schema = initCoreUsingSchemaVersion(v);+ final String ver = String.valueOf(v);++ // check defaults for fields where neither the field nor the field type+ // have any properties set on them+ for (String f : new String[] { "text", "xx_dyn_text",+ "bool", "xx_dyn_bool",+ "str", "xx_dyn_str" }) {++ SchemaField field = schema.getField(f);++ // 1.1: multiValued default changed+ assertEquals(f + " field's multiValued is wrong for ver=" + ver,+ (v < 1.1F), field.multiValued());++ // 1.2: omitTermFreqAndPositions default changed+ // to true for non TextField+ assertEquals(f + " field's type has wrong omitTfP for ver=" + ver,+ ( v < 1.2F ? false :+ ! (field.getType() instanceof TextField)),+ field.omitTermFreqAndPositions());++ // 1.4: autoGeneratePhraseQueries default changed to false+ if (field.getType() instanceof TextField) {+ TextField ft = (TextField) field.getType();+ assertEquals(f + " field's autoPhrase is wrong for ver=" + ver,+ (v < 1.4F), ft.getAutoGeneratePhraseQueries());+ }++ // 1.5: omitNorms default changed to true for non TextField+ assertEquals(f + " field's type has wrong omitNorm for ver=" + ver,+ ( v < 1.5F ? false :+ ! (field.getType() instanceof TextField)),+ field.omitNorms());+ }++ // regardless of version, explicit multiValued values on field or type+ // should be correct+ for (String f : new String[] { "multi_f", "multi_t",+ "ft_multi_f", "ft_multi_t",+ "xx_dyn_str_multi_f",+ "xx_dyn_str_multi_t",+ "xx_dyn_str_ft_multi_f",+ "xx_dyn_str_ft_multi_t" }) {++ boolean expected = f.endsWith("multi_t");+ SchemaField field = schema.getField(f);+ assertEquals(f + " field's multiValued is wrong for ver=" + ver,+ expected, field.multiValued());++ FieldType ft = field.getType();+ if (f.contains("ft_multi")) {+ // sanity check that we really are inheriting from fieldtype+ assertEquals(f + " field's multiValued doesn't match type for ver=" + ver,+ expected, ft.isMultiValued());+ } else {+ // for fields where the property is explicit, make sure+ // we aren't getting a false negative because someone changed the+ // schema and we're inheriting from fieldType+ assertEquals(f + " field's type has wrong multiValued is wrong for ver=" + ver,+ (v < 1.1F), ft.isMultiValued());++ }+ }++ // regardless of version, explicit omitTfP values on field or type+ // should be correct+ for (String f : new String[] { "strTfP_f", "strTfP_t",+ "txtTfP_f", "txtTfP_t",+ "ft_strTfP_f", "ft_strTfP_t",+ "ft_txtTfP_f", "ft_txtTfP_t",+ "xx_dyn_strTfP_f", "xx_dyn_strTfP_t",+ "xx_dyn_txtTfP_f", "xx_dyn_txtTfP_t",+ "xx_dyn_ft_strTfP_f", "xx_dyn_ft_strTfP_t",+ "xx_dyn_ft_txtTfP_f", "xx_dyn_ft_txtTfP_t" }) {++ boolean expected = f.endsWith("TfP_t");+ SchemaField field = schema.getField(f);+ assertEquals(f + " field's omitTfP is wrong for ver=" + ver,+ expected, field.omitTermFreqAndPositions());++ FieldType ft = field.getType();+ if (f.contains("ft_")) {+ // sanity check that we really are inheriting from fieldtype+ assertEquals(f + " field's omitTfP doesn't match type for ver=" + ver,+ expected, ft.hasProperty(FieldType.OMIT_TF_POSITIONS));+ } else {+ // for fields where the property is explicit, make sure+ // we aren't getting a false negative because someone changed the+ // schema and we're inheriting from fieldType+ assertEquals(f + " field's type has wrong omitTfP for ver=" + ver,+ ( v < 1.2F ? false :+ ! (field.getType() instanceof TextField)),+ ft.hasProperty(FieldType.OMIT_TF_POSITIONS));++ }+ }++ // regardless of version, explicit autophrase values on type+ // should be correct+ for (String f : new String[] { "ft_txt_phrase_f", "ft_txt_phrase_t",+ "xx_dyn_ft_txt_phrase_f",+ "xx_dyn_ft_txt_phrase_t" }) {++ boolean expected = f.endsWith("phrase_t");+ FieldType ft = schema.getFieldType(f);+ assertTrue("broken test, assert only valid on text fields: " + f,+ ft instanceof TextField);+ assertEquals(f + " field's autophrase is wrong for ver=" + ver,+ expected,+ ((TextField)ft).getAutoGeneratePhraseQueries() );+ }++ // regardless of version, explicit multiValued values on field or type+ // should be correct+ for (String f : new String[] { "strnorm_f", "strnorm_t",+ "txtnorm_f", "txtnorm_t",+ "ft_strnorm_f", "ft_strnorm_t",+ "ft_txtnorm_f", "ft_txtnorm_t",+ "xx_dyn_strnorm_f", "xx_dyn_strnorm_t",+ "xx_dyn_txtnorm_f", "xx_dyn_txtnorm_t",+ "xx_dyn_ft_strnorm_f", "xx_dyn_ft_strnorm_t",+ "xx_dyn_ft_txtnorm_f", "xx_dyn_ft_txtnorm_t" }) {++ boolean expected = f.endsWith("norm_t");+ SchemaField field = schema.getField(f);+ assertEquals(f + " field's omitNorm is wrong for ver=" + ver,+ expected, field.omitNorms());++ FieldType ft = field.getType();+ if (f.contains("ft_")) {+ // sanity check that we really are inheriting from fieldtype+ assertEquals(f + " field's omitNorm doesn't match type for ver=" + ver,+ expected, ft.hasProperty(FieldType.OMIT_NORMS));+ } else {+ // for fields where the property is explicit, make sure+ // we aren't getting a false negative because someone changed the+ // schema and we're inheriting from fieldType+ assertEquals(f + " field's type has wrong omitNorm for ver=" + ver,+ ( v < 1.5F ? false :+ ! (field.getType() instanceof TextField)),+ ft.hasProperty(FieldType.OMIT_NORMS));++ }+ }++ } finally {+ deleteCore();+ }+ }+ }++ public IndexSchema initCoreUsingSchemaVersion(final float ver)+ throws Exception {++ try {+ System.setProperty("solr.schema.test.ver", String.valueOf(ver));+ initCore( "solrconfig-basic.xml", "schema-behavior.xml" );+ IndexSchema s = h.getCore().getSchema();+ assertEquals("Schema version not set correctly",+ String.valueOf(ver),+ String.valueOf(s.getVersion()));+ return s;+ } finally {+ System.clearProperty("solr.schema.test.ver");+ }+ }++}