You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by br...@apache.org on 2024/01/19 16:11:56 UTC

(solr) branch branch_9x updated: SOLR-17121: Fix SchemaCodecFactory to get PostingsFormat and DocValues from field. (#2206)

This is an automated email from the ASF dual-hosted git repository.

broustant pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new fdc151a3114 SOLR-17121: Fix SchemaCodecFactory to get PostingsFormat and DocValues from field. (#2206)
fdc151a3114 is described below

commit fdc151a3114697a24924926793f5491b86283b67
Author: Bruno Roustant <33...@users.noreply.github.com>
AuthorDate: Fri Jan 19 11:54:47 2024 +0100

    SOLR-17121: Fix SchemaCodecFactory to get PostingsFormat and DocValues from field. (#2206)
---
 solr/CHANGES.txt                                   |  2 ++
 .../org/apache/solr/core/SchemaCodecFactory.java   |  4 +--
 .../collection1/conf/schema_postingsformat.xml     |  6 ++---
 .../org/apache/solr/schema/TestSchemaField.java    | 30 +++++++++++++++++++---
 4 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 14e06065420..4637f6ef64a 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -93,6 +93,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.java
index 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.xml
index 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.java
index 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());
+  }
 }