Apache Solr open-source search software
SOLR-17121: Fix SchemaCodecFactory to get PostingsFormat and DocValues from field. (#2206)
Bruno Roustant1624b4d7d2e3
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 728b3873805..58847504964 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -164,6 +164,8 @@ Bug Fixes* SOLR-17090: The v2 "delete alias" API no longer errantly returns a 405 status code (Jason Gerlowski)+* SOLR-17121: Fix SchemaCodecFactory to get PostingsFormat and DocValues from field. (Bruno Roustant, David Smiley)+Dependency Upgrades---------------------* SOLR-17012: Update Apache Hadoop to 3.3.6 and Apache Curator to 5.5.0 (Kevin Risden)diff --git a/solr/core/src/java/org/apache/solr/core/SchemaCodecFactory.java b/solr/core/src/java/org/apache/solr/core/SchemaCodecFactory.javaindex 8f4fe26ebbc..0197a6b4b81 100644--- a/solr/core/src/java/org/apache/solr/core/SchemaCodecFactory.java+++ b/solr/core/src/java/org/apache/solr/core/SchemaCodecFactory.java@@ -102,7 +102,7 @@ public class SchemaCodecFactory extends CodecFactory implements SolrCoreAware {public PostingsFormat getPostingsFormatForField(String field) {final SchemaField schemaField = core.getLatestSchema().getFieldOrNull(field);if (schemaField != null) {- String postingsFormatName = schemaField.getType().getPostingsFormat();+ String postingsFormatName = schemaField.getPostingsFormat();if (postingsFormatName != null) {return PostingsFormat.forName(postingsFormatName);}@@ -114,7 +114,7 @@ public class SchemaCodecFactory extends CodecFactory implements SolrCoreAware {public DocValuesFormat getDocValuesFormatForField(String field) {final SchemaField schemaField = core.getLatestSchema().getFieldOrNull(field);if (schemaField != null) {- String docValuesFormatName = schemaField.getType().getDocValuesFormat();+ String docValuesFormatName = schemaField.getDocValuesFormat();if (docValuesFormatName != null) {return DocValuesFormat.forName(docValuesFormatName);}diff --git a/solr/core/src/test-files/solr/collection1/conf/schema_postingsformat.xml b/solr/core/src/test-files/solr/collection1/conf/schema_postingsformat.xmlindex 7d452a59d17..32dd7403d28 100644--- a/solr/core/src/test-files/solr/collection1/conf/schema_postingsformat.xml+++ b/solr/core/src/test-files/solr/collection1/conf/schema_postingsformat.xml@@ -19,14 +19,14 @@<fieldType name="str_none" class="solr.StrField"/><fieldType name="str_direct_asserting" class="solr.StrField" postingsFormat="Direct" docValuesFormat="Asserting"/>- <fieldType name="str_standard_simple" class="solr.StrField" postingsFormat="Lucene84" docValuesFormat="SimpleTextDocValuesFormat"/>+ <fieldType name="str_standard_simple" class="solr.StrField" postingsFormat="Lucene84" docValuesFormat="Lucene80"/><field name="str_none_f" type="str_none"/><field name="str_direct_asserting_f" type="str_direct_asserting"/><field name="str_standard_simple_f" type="str_standard_simple"/><field name="str_none_lucene80_f" type="str_none" postingsFormat="Lucene80"/>- <field name="str_standard_lucene80_f" type="str_standard_simple" postingsFormat="Lucene80"/>+ <field name="str_standard_lucene90_f" type="str_standard_simple" postingsFormat="Lucene90"/><field name="str_none_asserting_f" type="str_none" docValuesFormat="Asserting"/><field name="str_standard_asserting_f" type="str_standard_simple" docValuesFormat="Asserting"/>@@ -36,6 +36,6 @@<dynamicField name="*_lucene70" type="str_none" postingsFormat="Lucene70"/><dynamicField name="*_asserting" type="str_none" docValuesFormat="Asserting"/>- <dynamicField name="*_simple" type="str_direct_asserting" docValuesFormat="SimpleTextDocValuesFormat"/>+ <dynamicField name="*_simple" type="str_direct_asserting" docValuesFormat="Lucene80"/></schema>diff --git a/solr/core/src/test/org/apache/solr/schema/TestSchemaField.java b/solr/core/src/test/org/apache/solr/schema/TestSchemaField.javaindex eb48ac05ca2..e404c48a238 100644--- a/solr/core/src/test/org/apache/solr/schema/TestSchemaField.java+++ b/solr/core/src/test/org/apache/solr/schema/TestSchemaField.java@@ -17,6 +17,10 @@package org.apache.solr.schema;+import org.apache.lucene.codecs.DocValuesFormat;+import org.apache.lucene.codecs.PostingsFormat;+import org.apache.lucene.codecs.perfield.PerFieldDocValuesFormat;+import org.apache.lucene.codecs.perfield.PerFieldPostingsFormat;import org.apache.solr.SolrTestCaseJ4;import org.junit.Before;import org.junit.BeforeClass;@@ -36,7 +40,7 @@ public class TestSchemaField extends SolrTestCaseJ4 {public void testFieldTypes() {assertFieldTypeFormats("str_none", null, null);assertFieldTypeFormats("str_direct_asserting", "Direct", "Asserting");- assertFieldTypeFormats("str_standard_simple", "Lucene84", "SimpleTextDocValuesFormat");+ assertFieldTypeFormats("str_standard_simple", "Lucene84", "Lucene80");}private void assertFieldTypeFormats(@@ -64,10 +68,10 @@ public class TestSchemaField extends SolrTestCaseJ4 {public void testFields() {assertFieldFormats("str_none_f", null, null);assertFieldFormats("str_direct_asserting_f", "Direct", "Asserting");- assertFieldFormats("str_standard_simple_f", "Lucene84", "SimpleTextDocValuesFormat");+ assertFieldFormats("str_standard_simple_f", "Lucene84", "Lucene80");assertFieldFormats("str_none_lucene80_f", "Lucene80", null);- assertFieldFormats("str_standard_lucene80_f", "Lucene80", "SimpleTextDocValuesFormat");+ assertFieldFormats("str_standard_lucene90_f", "Lucene90", "Lucene80");assertFieldFormats("str_none_asserting_f", null, "Asserting");assertFieldFormats("str_standard_asserting_f", "Lucene84", "Asserting");@@ -79,7 +83,7 @@ public class TestSchemaField extends SolrTestCaseJ4 {assertFieldFormats("any_lucene70", "Lucene70", null);assertFieldFormats("any_asserting", null, "Asserting");- assertFieldFormats("any_simple", "Direct", "SimpleTextDocValuesFormat");+ assertFieldFormats("any_simple", "Direct", "Lucene80");}private void assertFieldFormats(@@ -103,4 +107,22 @@ public class TestSchemaField extends SolrTestCaseJ4 {expectedDocValuesFormat,f.getDocValuesFormat());}++ public void testSchemaCodecFactory() {+ // Verify that the PostingsFormat is the one overridden in the field, not the field type.+ PostingsFormat postingsFormat = h.getCore().getCodec().postingsFormat();+ assertTrue(postingsFormat instanceof PerFieldPostingsFormat);+ PerFieldPostingsFormat perFieldPostingsFormat = (PerFieldPostingsFormat) postingsFormat;+ assertEquals(+ "Lucene90",+ perFieldPostingsFormat.getPostingsFormatForField("str_standard_lucene90_f").getName());++ // Verify that the DocValuesFormat is the one overridden in the field, not the field type.+ DocValuesFormat docValuesFormat = h.getCore().getCodec().docValuesFormat();+ assertTrue(docValuesFormat instanceof PerFieldDocValuesFormat);+ PerFieldDocValuesFormat perFieldPDocValuesFormat = (PerFieldDocValuesFormat) docValuesFormat;+ assertEquals(+ "Asserting",+ perFieldPDocValuesFormat.getDocValuesFormatForField("str_standard_asserting_f").getName());+ }}