Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UpsertCondition due to Solr 7 encoding of String types in javabin… #66

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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"));
Expand Down
Loading