diff --git a/solr/core/src/java/org/apache/solr/update/processor/UpsertCondition.java b/solr/core/src/java/org/apache/solr/update/processor/UpsertCondition.java index 4af24872ff3..0b8888bd67c 100644 --- a/solr/core/src/java/org/apache/solr/update/processor/UpsertCondition.java +++ b/solr/core/src/java/org/apache/solr/update/processor/UpsertCondition.java @@ -399,13 +399,13 @@ private static String getFieldFromDoc(String fieldName, SolrInputDocument doc) { return null; } Object fieldValue = doc.getFieldValue(fieldName); - if (fieldValue instanceof String) { - return (String)fieldValue; + if (fieldValue instanceof CharSequence) { + return fieldValue.toString(); } if (fieldValue instanceof Map) { final Object setValue = ((Map)fieldValue).get("set"); - if (setValue instanceof String) { - return (String)setValue; + if (setValue instanceof CharSequence) { + return setValue.toString(); } } // Cannot support non-String types or collection (multi-valued field) types diff --git a/solr/core/src/test/org/apache/solr/update/processor/UpsertConditionTest.java b/solr/core/src/test/org/apache/solr/update/processor/UpsertConditionTest.java index ad6dee1f1f0..1fd09e0ec90 100644 --- a/solr/core/src/test/org/apache/solr/update/processor/UpsertConditionTest.java +++ b/solr/core/src/test/org/apache/solr/update/processor/UpsertConditionTest.java @@ -10,6 +10,7 @@ import com.google.common.collect.ListMultimap; import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrInputDocument; +import org.apache.solr.common.util.ByteArrayUtf8CharSequence; import org.apache.solr.common.util.NamedList; import org.junit.Test; @@ -872,6 +873,19 @@ public void givenConcatWithOldDoc_whenRunning() { assertThat(newDoc.getFieldValue("sku"), is("MacbookSilver")); } + { + // Same test but simulating how the javabin format encodes strings + SolrInputDocument newDoc = new SolrInputDocument(); + newDoc.setField("model_name", new ByteArrayUtf8CharSequence("Macbook")); + SolrInputDocument oldDoc = new SolrInputDocument(); + oldDoc.setField("model_name", "Powerbook"); + oldDoc.setField("colour", "Silver"); + oldDoc.setField("sku", "PowerbookSilver"); + assertTrue(condition.matches(oldDoc, newDoc)); + assertThat(condition.run(oldDoc, newDoc), is(UpsertCondition.ActionType.CONCAT)); + assertThat(newDoc.getFieldValue("sku"), is("MacbookSilver")); + } + { SolrInputDocument newDoc = new SolrInputDocument(); newDoc.setField("model_name", "Macbook"); @@ -966,6 +980,20 @@ public void givenConcatWithAtomicUpdates_whenRunning() { assertThat(newDoc.getFieldValue("sku"), is("MacbookSilver")); } + { + // Same test but simulating how the javabin format encodes strings + SolrInputDocument newDoc = new SolrInputDocument(); + newDoc.setField("model_name", + Collections.singletonMap("set", new ByteArrayUtf8CharSequence("Macbook"))); + SolrInputDocument oldDoc = new SolrInputDocument(); + oldDoc.setField("model_name", "Powerbook"); + oldDoc.setField("colour", "Silver"); + oldDoc.setField("sku", "PowerbookSilver"); + assertTrue(condition.matches(oldDoc, newDoc)); + assertThat(condition.run(oldDoc, newDoc), is(UpsertCondition.ActionType.CONCAT)); + assertThat(newDoc.getFieldValue("sku"), is("MacbookSilver")); + } + { SolrInputDocument newDoc = new SolrInputDocument(); newDoc.setField("unrelated_field", Collections.singletonMap("set", "English"));