Apache Lucene open-source search software
SOLR-14090: fix delete-copy-field when source is dynamic field
Munendra S Nc91dd9d0e433
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 745401a349a..640e93c52f3 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -259,6 +259,8 @@ Bug Fixes* SOLR-13897: Fix unsafe publication of Terms object in ZkShardTerms that can cause visibility issuesand race conditions under contention. (shalin)+* SOLR-14090: Handle the case in `delete-copy-field` when source is a dynamic field (Frank Iversen, Munendra S N)+Other Changes---------------------diff --git a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.javaindex 57b0c90e90b..7e16880f35e 100644--- a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java+++ b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java@@ -860,7 +860,11 @@ public final class ManagedIndexSchema extends IndexSchema {break;}}- } else { // non-dynamic copy field directive+ }++ if (!found) {+ // non-dynamic copy field directive.+ // Here, source field could either exists in schema or match a dynamic ruleList<CopyField> copyFieldList = copyFieldsMap.get(source);if (copyFieldList != null) {for (Iterator<CopyField> iter = copyFieldList.iterator() ; iter.hasNext() ; ) {diff --git a/solr/core/src/test/org/apache/solr/rest/schema/TestBulkSchemaAPI.java b/solr/core/src/test/org/apache/solr/rest/schema/TestBulkSchemaAPI.javaindex d35f8d1b0c9..68c7811f121 100644--- a/solr/core/src/test/org/apache/solr/rest/schema/TestBulkSchemaAPI.java+++ b/solr/core/src/test/org/apache/solr/rest/schema/TestBulkSchemaAPI.java@@ -675,7 +675,77 @@ public class TestBulkSchemaAPI extends RestTestBase {assertNotNull("'attr_*' dynamic field does not exist in the schema", m);assertEquals("string", m.get("type"));}-++ public void testCopyFieldRules() throws Exception {+ RestTestHarness harness = restTestHarness;++ Map m = getObj(harness, "name", "fields");+ assertNotNull("'name' field does not exist in the schema", m);++ m = getObj(harness, "bind", "fields");+ assertNotNull("'bind' field does not exist in the schema", m);++ List l = getSourceCopyFields(harness, "bleh_s");+ assertTrue("'bleh_s' copyField rule exists in the schema", l.isEmpty());++ String payload = "{\n" ++ " 'add-copy-field' : {\n" ++ " 'source' :'bleh_s',\n" ++ " 'dest':'name'\n" ++ " }\n" ++ " }\n";+ String response = harness.post("/schema", json(payload));++ Map map = (Map) fromJSONString(response);+ assertNull(response, map.get("error"));++ l = getSourceCopyFields(harness, "bleh_s");+ assertFalse("'bleh_s' copyField rule doesn't exist", l.isEmpty());+ assertEquals("bleh_s", ((Map)l.get(0)).get("source"));+ assertEquals("name", ((Map)l.get(0)).get("dest"));++ // delete copy field rule+ payload = "{\n" ++ " 'delete-copy-field' : {\n" ++ " 'source' :'bleh_s',\n" ++ " 'dest':'name'\n" ++ " }\n" ++ " }\n";++ response = harness.post("/schema", json(payload));+ map = (Map) fromJSONString(response);+ assertNull(response, map.get("error"));+ l = getSourceCopyFields(harness, "bleh_s");+ assertTrue("'bleh_s' copyField rule exists in the schema", l.isEmpty());++ // copy and delete with multiple destination+ payload = "{\n" ++ " 'add-copy-field' : {\n" ++ " 'source' :'bleh_s',\n" ++ " 'dest':['name','bind']\n" ++ " }\n" ++ " }\n";+ response = harness.post("/schema", json(payload));+ map = (Map) fromJSONString(response);+ assertNull(response, map.get("error"));++ l = getSourceCopyFields(harness, "bleh_s");+ assertEquals(2, l.size());++ payload = "{\n" ++ " 'delete-copy-field' : {\n" ++ " 'source' :'bleh_s',\n" ++ " 'dest':['name','bind']\n" ++ " }\n" ++ " }\n";++ response = harness.post("/schema", json(payload));+ map = (Map) fromJSONString(response);+ assertNull(response, map.get("error"));+ l = getSourceCopyFields(harness, "bleh_s");+ assertTrue("'bleh_s' copyField rule exists in the schema", l.isEmpty());+ }+public void testDeleteAndReplace() throws Exception {RestTestHarness harness = restTestHarness;@@ -904,6 +974,7 @@ public class TestBulkSchemaAPI extends RestTestBase {map = (Map) fromJSONString(response);assertNull(map.get("error"));}+public void testSortableTextFieldWithAnalyzer() throws Exception {String fieldTypeName = "sort_text_type";String fieldName = "sort_text";@@ -958,7 +1029,7 @@ public class TestBulkSchemaAPI extends RestTestBase {}}-+@Testpublic void testAddNewFieldAndQuery() throws Exception {getSolrClient().add(Arrays.asList(@@ -976,7 +1047,7 @@ public class TestBulkSchemaAPI extends RestTestBase {int size = getSolrClient().query(query).getResults().size();assertEquals(1, size);}-+public void testSimilarityParser() throws Exception {RestTestHarness harness = restTestHarness;