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:24:55 UTC
[solr] branch main 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 main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new b8ca0ce23e2 SOLR-16502: Multiple CopyField should not limit to first maxChars (#1141)
b8ca0ce23e2 is described below
commit b8ca0ce23e2ebe1b33c85b71fc61ab9cf8411a35
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 0ba100e6c5a..c39ea1b0c7d 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -84,6 +84,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();