You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ep...@apache.org on 2023/10/13 21:09:24 UTC

[solr] branch main updated: SOLR-6853: Add slash support for Managed Resources (synonyms and stopwords) (#1829)

This is an automated email from the ASF dual-hosted git repository.

epugh 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 e0b34d7411f SOLR-6853: Add slash support for Managed Resources (synonyms and stopwords) (#1829)
e0b34d7411f is described below

commit e0b34d7411f27640fc5eb6016480acdaa48c76f9
Author: Nikita Rusetskii <ru...@outlook.com>
AuthorDate: Sat Oct 14 04:09:16 2023 +0700

    SOLR-6853: Add slash support for Managed Resources (synonyms and stopwords) (#1829)
    
    * SOLR-6853: Fix slash parsing in RestManager when a text has an embedded `/` character
    
    Co-authored-by: Eric Pugh <ep...@opensourceconnections.com>
---
 solr/CHANGES.txt                                   |  4 +--
 .../src/java/org/apache/solr/rest/RestManager.java | 40 ++++++++++++----------
 .../analysis/TestManagedStopFilterFactory.java     | 12 +++++++
 .../TestManagedSynonymGraphFilterFactory.java      | 11 ++++++
 4 files changed, 47 insertions(+), 20 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 525a2fad720..5c197f8f920 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -26,7 +26,7 @@ Optimizations
 
 Bug Fixes
 ---------------------
-(No changes)
+
 
 Deprecation Removals
 ----------------------
@@ -86,7 +86,7 @@ Optimizations
 
 Bug Fixes
 ---------------------
-(No changes)
+* SOLR-6853: Allow '/' characters in the text managed by Managed Resources API. (Nikita Rusetskii via Eric Pugh)
 
 Dependency Upgrades
 ---------------------
diff --git a/solr/core/src/java/org/apache/solr/rest/RestManager.java b/solr/core/src/java/org/apache/solr/rest/RestManager.java
index d83f6bc7363..1078168628b 100644
--- a/solr/core/src/java/org/apache/solr/rest/RestManager.java
+++ b/solr/core/src/java/org/apache/solr/rest/RestManager.java
@@ -288,27 +288,31 @@ public class RestManager {
       final String resourceId = resolveResourceId(solrRequest.getPath());
       managedResource = restManager.getManagedResourceOrNull(resourceId);
       if (managedResource == null) {
-        // see if we have a registered endpoint one-level up ...
-        int lastSlashAt = resourceId.lastIndexOf('/');
-        if (lastSlashAt != -1) {
-          String parentResourceId = resourceId.substring(0, lastSlashAt);
-          log.info(
+        int lastSlashAt;
+        String parentResourceId;
+        String initialResourceId = resourceId;
+        // Check if we have a registered endpoint, going one level up each time...
+        do {
+          lastSlashAt = initialResourceId.lastIndexOf('/');
+          parentResourceId = resourceId.substring(0, lastSlashAt);
+          log.debug(
               "Resource not found for {}, looking for parent: {}", resourceId, parentResourceId);
           managedResource = restManager.getManagedResourceOrNull(parentResourceId);
-          if (managedResource != null) {
-            // verify this resource supports child resources
-            if (!(managedResource instanceof ManagedResource.ChildResourceSupport)) {
-              String errMsg =
-                  String.format(
-                      Locale.ROOT,
-                      "%s does not support child resources!",
-                      managedResource.getResourceId());
-              throw new SolrException(ErrorCode.BAD_REQUEST, errMsg);
-            }
-
-            childId = resourceId.substring(lastSlashAt + 1);
-            log.info("Found parent resource {} for child: {}", parentResourceId, childId);
+          initialResourceId = parentResourceId;
+        } while (managedResource == null && initialResourceId.lastIndexOf("/") != -1);
+        if (managedResource != null) {
+          // verify this resource supports child resources
+          if (!(managedResource instanceof ManagedResource.ChildResourceSupport)) {
+            String errMsg =
+                String.format(
+                    Locale.ROOT,
+                    "%s does not support child resources!",
+                    managedResource.getResourceId());
+            throw new SolrException(ErrorCode.BAD_REQUEST, errMsg);
           }
+
+          childId = resourceId.substring(lastSlashAt + 1);
+          log.debug("Found parent resource {} for child: {}", parentResourceId, childId);
         }
       }
 
diff --git a/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedStopFilterFactory.java b/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedStopFilterFactory.java
index a1fff16edc0..d3aa476693c 100644
--- a/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedStopFilterFactory.java
+++ b/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedStopFilterFactory.java
@@ -191,6 +191,18 @@ public class TestManagedStopFilterFactory extends RestTestBase {
 
     // should fail with 404 as foo doesn't exist
     assertJDelete(endpoint + "/foo", "/error/code==404");
+
+    // test for SOLR-6853 - should be able to delete stopwords with slash
+    assertJPut(
+        endpoint,
+        Utils.toJSONString(Arrays.asList("cheerful/joyful", "sleepy/tired")),
+        "/responseHeader/status==0");
+
+    // verify delete works
+    assertJDelete(endpoint + "/cheerful/joyful", "/responseHeader/status==0");
+
+    // should fail with 404 as some/thing doesn't exist
+    assertJDelete(endpoint + "/cheerful/joyful", "/error/code==404");
   }
 
   /** Can we add and remove stopwords with umlauts */
diff --git a/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedSynonymGraphFilterFactory.java b/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedSynonymGraphFilterFactory.java
index c5363c7f251..f27bdbc0d5d 100644
--- a/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedSynonymGraphFilterFactory.java
+++ b/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedSynonymGraphFilterFactory.java
@@ -249,6 +249,17 @@ public class TestManagedSynonymGraphFilterFactory extends RestTestBase {
         "/entertaining==['entertaining','funny','jocular','whimsical']");
     assertJQ(endpoint + "/jocular", "/jocular==['entertaining','funny','jocular','whimsical']");
     assertJQ(endpoint + "/whimsical", "/whimsical==['entertaining','funny','jocular','whimsical']");
+
+    // test for SOLR-6853 - should be able to delete synonyms with slash
+    Map<String, List<String>> slashSyns = new HashMap<>();
+    slashSyns.put("cheerful/joyful", List.of("sleepy/tired"));
+    assertJPut(endpoint, toJSONString(slashSyns), "/responseHeader/status==0");
+
+    // verify delete works
+    assertJDelete(endpoint + "/cheerful/joyful", "/responseHeader/status==0");
+
+    // should fail with 404 as some/thing doesn't exist
+    assertJDelete(endpoint + "/cheerful/joyful", "/error/code==404");
   }
 
   /** Can we add and remove stopwords with umlauts */