You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by cp...@apache.org on 2022/11/04 12:07:57 UTC
[solr] branch branch_9_1 updated: SOLR-16502: Multiple CopyField should not limit to first maxChars (#1141)
This is an automated email from the ASF dual-hosted git repository.
cpoerschke pushed a commit to branch branch_9_1
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_9_1 by this push:
new 4c2fde2e472 SOLR-16502: Multiple CopyField should not limit to first maxChars (#1141)
4c2fde2e472 is described below
commit 4c2fde2e472e30a164d5d1bbca0629ca62bf15b3
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>
(cherry picked from commit 7ab1d3300c901cd4ea46ffaca63f7d4ed1f13001)
Resolved Conflicts:
solr/CHANGES.txt
---
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 288b0b64788..d5a9c38ef96 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -175,6 +175,8 @@ Bug Fixes
* SOLR-14679: Fix continuously growing TLOGs on TLOG replicas (Viktor Molnár via Houston Putman)
+* SOLR-16502: Multiple CopyField should not limit to first maxChars (Fredrik Rodland, Kevin Risden)
+
Other Changes
---------------------
* SOLR-16351: Upgrade Carrot2 to 4.4.3, upgrade randomizedtesting to 2.8.0. (Dawid Weiss)
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 6455514d6f8..9e8e008b9a6 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 96b39d0d035..8a1dad952fa 100644
--- a/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java
+++ b/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java
@@ -314,6 +314,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();