You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by kr...@apache.org on 2022/10/27 19:29:35 UTC

[solr] branch branch_9x updated: SOLR-16502: Multiple CopyField should not limit to first maxChars (#1141)

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

krisden 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 7ab1d3300c9 SOLR-16502: Multiple CopyField should not limit to first maxChars (#1141)
7ab1d3300c9 is described below

commit 7ab1d3300c901cd4ea46ffaca63f7d4ed1f13001
Author: Kevin Risden <ri...@users.noreply.github.com>
AuthorDate: Thu Oct 27 15:24:48 2022 -0400

    SOLR-16502: Multiple CopyField should not limit to first maxChars (#1141)
    
    Co-authored-by: Christine Poerschke <cp...@apache.org>
---
 solr/CHANGES.txt                                   |  2 ++
 .../org/apache/solr/update/DocumentBuilder.java    |  7 +++---
 .../test-files/solr/collection1/conf/schema.xml    |  6 ++++-
 .../apache/solr/update/DocumentBuilderTest.java    | 28 ++++++++++++++++++++++
 4 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 7f1124c029f..5ff926967aa 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -59,6 +59,8 @@ Bug Fixes
 
 * SOLR-16274: HEAD request for managed resource returns 500 Server Error (Kevin Risden)
 
+* SOLR-16502: Multiple CopyField should not limit to first maxChars (Fredrik Rodland, Kevin Risden)
+
 Build
 ---------------------
 * Upgrade forbiddenapis to 3.4 (Uwe Schindler)
diff --git a/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java b/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java
index 348de18f92c..4a6a5308c59 100644
--- a/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java
+++ b/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java
@@ -306,7 +306,7 @@ public class DocumentBuilder {
   }
 
   private static boolean addCopyFields(
-      Object originalFieldValue,
+      final Object originalFieldValue,
       FieldType originalFieldType,
       List<CopyField> copyFields,
       boolean forInPlaceUpdate,
@@ -336,16 +336,17 @@ public class DocumentBuilder {
                 + ": "
                 + originalFieldValue);
       }
+      Object fieldValue = originalFieldValue;
       // Perhaps trim the length of a copy field
       if (originalFieldValue instanceof CharSequence && cf.getMaxChars() > 0) {
-        originalFieldValue = cf.getLimitedValue(originalFieldValue.toString());
+        fieldValue = cf.getLimitedValue(originalFieldValue.toString());
       }
 
       // TODO ban copyField populating uniqueKeyField; too problematic to support
       addField(
           out,
           destinationField,
-          originalFieldValue,
+          fieldValue,
           destinationField.getName().equals(uniqueKeyFieldName) ? false : forInPlaceUpdate);
       // record the field as having a originalFieldValue
       usedFields.add(destinationField.getName());
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema.xml b/solr/core/src/test-files/solr/collection1/conf/schema.xml
index 570c19bc561..ec039ac0bf0 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema.xml
@@ -704,7 +704,9 @@
   <field name="severity" type="severityType" docValues="true" indexed="true" stored="true" multiValued="false"/>
 
   <field name="max_chars" type="string" indexed="false" stored="true"/>
-  
+  <field name="no_max_chars" type="string" indexed="false" stored="true"/>
+  <field name="large_max_chars" type="string" indexed="false" stored="true"/>
+
   <!-- Dense Vector-->
   <field name="vector" type="knn_vector_cosine" indexed="true" stored="true"/>
   <field name="vector2" type="knn_vector_dot_product" indexed="true" stored="true"/>
@@ -917,6 +919,8 @@
   <copyField source="*_path" dest="*_ancestor"/>
 
   <copyField source="title" dest="max_chars" maxChars="10"/>
+  <copyField source="title" dest="no_max_chars" />
+  <copyField source="title" dest="large_max_chars" maxChars="10000"/>
   <copyField source="vector" dest="vector2"/>
   <copyField source="vector3" dest="vector_f_p"/>
   <copyField source="vector4" dest="vector5"/>
diff --git a/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java b/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java
index 735fe27c402..e708035571c 100644
--- a/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java
+++ b/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java
@@ -313,6 +313,34 @@ public class DocumentBuilderTest extends SolrTestCaseJ4 {
     assertEquals(truncatedValue, out.get("max_chars"));
   }
 
+  @Test
+  public void testMultipleCopyFieldMaxChars() {
+    SolrCore core = h.getCore();
+
+    String testValue = "this is more than 10 characters";
+    String truncatedValue = "this is mo";
+
+    // maxChars with a string value
+    SolrInputDocument doc = new SolrInputDocument();
+    doc.addField("title", testValue);
+
+    Document out = DocumentBuilder.toDocument(doc, core.getLatestSchema());
+    assertEquals(testValue, out.get("title"));
+    assertEquals(truncatedValue, out.get("max_chars"));
+    assertEquals(testValue, out.get("no_max_chars"));
+    assertEquals(testValue, out.get("large_max_chars"));
+
+    // maxChars with a ByteArrayUtf8CharSequence
+    doc = new SolrInputDocument();
+    doc.addField("title", new ByteArrayUtf8CharSequence(testValue));
+
+    out = DocumentBuilder.toDocument(doc, core.getLatestSchema());
+    assertEquals(testValue, out.get("title"));
+    assertEquals(truncatedValue, out.get("max_chars"));
+    assertEquals(testValue, out.get("no_max_chars"));
+    assertEquals(testValue, out.get("large_max_chars"));
+  }
+
   @Test
   public void denseVector_shouldReturnOneIndexableFieldAndOneStoredFieldPerVectorElement() {
     SolrCore core = h.getCore();