lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From munendr...@apache.org
Subject [lucene-solr] 02/02: SOLR-14090: fix delete-copy-field when source is dynamic field
Date Tue, 04 Feb 2020 16:16:59 GMT
This is an automated email from the ASF dual-hosted git repository.

munendrasn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit c91dd9d0e4336cb8fd24d4be2d53342f1e3a8cd3
Author: Munendra S N <munendrasn@apache.org>
AuthorDate: Tue Feb 4 21:33:31 2020 +0530

    SOLR-14090: fix delete-copy-field when source is dynamic field
---
 solr/CHANGES.txt                                   |  2 +
 .../org/apache/solr/schema/ManagedIndexSchema.java |  6 +-
 .../apache/solr/rest/schema/TestBulkSchemaAPI.java | 77 +++++++++++++++++++++-
 3 files changed, 81 insertions(+), 4 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 745401a..640e93c 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
issues
   and 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.java
index 57b0c90..7e16880 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 rule
       List<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.java
index d35f8d1..68c7811 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 {
     }
     
   }
-  
+
   @Test
   public 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;
 


Mime
View raw message