You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2019/08/25 22:57:23 UTC

[lucene-solr] branch master updated: SOLR-13699 - maxChars no longer working on CopyField with Javabin

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

noble pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/master by this push:
     new 64a4ca5  SOLR-13699 - maxChars no longer working on CopyField with Javabin
64a4ca5 is described below

commit 64a4ca57a89ad05085e60571fcea3b532de28e8e
Author: Chris Troullis <cp...@gmail.com>
AuthorDate: Sun Aug 25 18:57:17 2019 -0400

    SOLR-13699 - maxChars no longer working on CopyField with Javabin
---
 .../org/apache/solr/update/DocumentBuilder.java    |  4 ++--
 .../test-files/solr/collection1/conf/schema.xml    |  4 ++++
 .../apache/solr/update/DocumentBuilderTest.java    | 25 ++++++++++++++++++++++
 3 files changed, 31 insertions(+), 2 deletions(-)

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 90694ff..543a4cb 100644
--- a/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java
+++ b/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java
@@ -196,8 +196,8 @@ public class DocumentBuilder {
 
                 // Perhaps trim the length of a copy field
                 Object val = v;
-                if( val instanceof String && cf.getMaxChars() > 0 ) {
-                  val = cf.getLimitedValue((String)val);
+                if( val instanceof CharSequence && cf.getMaxChars() > 0 ) {
+                    val = cf.getLimitedValue(val.toString());
                 }
 
                 addField(out, destinationField, val,
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 31fd9e5..e0a96cc 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema.xml
@@ -651,6 +651,8 @@
   <!-- EnumType -->
   <field name="severity" type="severityType" docValues="true" indexed="true" stored="true" multiValued="false"/>
 
+  <field name="max_chars" type="string" indexed="false" stored="true"/>
+
 
   <!-- Dynamic field definitions.  If a field name is not found, dynamicFields
        will be used if the name matches any of the patterns.
@@ -850,6 +852,8 @@
   <copyField source="*_dynamic" dest="dynamic_*"/>
   <copyField source="*_path" dest="*_ancestor"/>
 
+  <copyField source="title" dest="max_chars" maxChars="10"/>
+
   <!-- example of a custom similarity -->
   <similarity class="solr.CustomSimilarityFactory">
     <str name="echo">I am your default sim</str>
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 bf819a0..1b0794b 100644
--- a/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java
+++ b/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java
@@ -30,6 +30,7 @@ import org.apache.solr.common.SolrDocument;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.SolrInputDocument;
 import org.apache.solr.common.SolrInputField;
+import org.apache.solr.common.util.ByteArrayUtf8CharSequence;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.schema.FieldType;
 import org.junit.After;
@@ -274,4 +275,28 @@ public class DocumentBuilderTest extends SolrTestCaseJ4 {
     assertTrue(field.stringValue().startsWith("STORED V3|"));
   }
 
+  @Test
+  public void testCopyFieldMaxChars() {
+    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"));
+
+    //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"));
+  }
+
 }