Apache Solr open-source search software
SOLR-6853: Add slash support for Managed Resources (synonyms and stopwords) (#1829)
Nikita Rusetskiie0b34d7411f2
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 525a2fad720..5c197f8f920 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -26,7 +26,7 @@ OptimizationsBug Fixes----------------------(No changes)+Deprecation Removals----------------------@@ -86,7 +86,7 @@ OptimizationsBug 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.javaindex 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.javaindex 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 existassertJDelete(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.javaindex 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 */