lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thelabd...@apache.org
Subject svn commit: r1616366 - in /lucene/dev/branches/branch_4x/solr: ./ core/src/java/org/apache/solr/rest/ core/src/test-files/solr/collection1/conf/ core/src/test/org/apache/solr/rest/ core/src/test/org/apache/solr/rest/schema/analysis/
Date Wed, 06 Aug 2014 22:28:53 GMT
Author: thelabdude
Date: Wed Aug  6 22:28:52 2014
New Revision: 1616366

URL: http://svn.apache.org/r1616366
Log:
SOLR-6163: Correctly decode special characters in managed stopwords and synonym endpoints.

Modified:
    lucene/dev/branches/branch_4x/solr/CHANGES.txt
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/rest/RestManager.java
    lucene/dev/branches/branch_4x/solr/core/src/test-files/solr/collection1/conf/schema-rest.xml
    lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/rest/TestRestManager.java
    lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedStopFilterFactory.java
    lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedSynonymFilterFactory.java

Modified: lucene/dev/branches/branch_4x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/CHANGES.txt?rev=1616366&r1=1616365&r2=1616366&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/solr/CHANGES.txt Wed Aug  6 22:28:52 2014
@@ -169,6 +169,9 @@ Bug Fixes
 * SOLR-6264: Distributed commit and optimize are executed serially across all 
   replicas. (Mark Miller, Timothy Potter)
 
+* SOLR-6163: Correctly decode special characters in managed stopwords and synonym endpoints.
+  (Vitaliy Zhovtyuk, Timo Schmidt via Timothy Potter)
+
 Optimizations
 ---------------------
 

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/rest/RestManager.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/rest/RestManager.java?rev=1616366&r1=1616365&r2=1616366&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/rest/RestManager.java
(original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/rest/RestManager.java
Wed Aug  6 22:28:52 2014
@@ -66,6 +66,8 @@ public class RestManager {
   // used for validating resourceIds provided during registration
   private static final Pattern resourceIdRegex = Pattern.compile("(/config|/schema)(/.*)");
 
+  private static final boolean DECODE = true;
+
   /**
    * Used internally to keep track of registrations during core initialization
    */
@@ -251,21 +253,23 @@ public class RestManager {
    * to. ManagedResource implementations are heavy-weight objects that live for the duration
of
    * a SolrCore, so this class acts as the proxy between Restlet and a ManagedResource when
    * doing request processing.
+   *
    */
-  public static class ManagedEndpoint extends BaseSolrResource 
+  public static class ManagedEndpoint extends BaseSolrResource
       implements GETable, PUTable, POSTable, DELETEable
   {
     /**
      * Determines the ManagedResource resourceId from the Restlet request.
      */
-    public static String resolveResourceId(Request restletReq) {
+    public static String resolveResourceId(Request restletReq)  {
       String resourceId = restletReq.getResourceRef().
-          getRelativeRef(restletReq.getRootRef().getParentRef()).getPath();
+          getRelativeRef(restletReq.getRootRef().getParentRef()).getPath(DECODE);
       
       // all resources are registered with the leading slash
       if (!resourceId.startsWith("/"))
         resourceId = "/"+resourceId;
-      
+
+
       return resourceId;
     }
     

Modified: lucene/dev/branches/branch_4x/solr/core/src/test-files/solr/collection1/conf/schema-rest.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test-files/solr/collection1/conf/schema-rest.xml?rev=1616366&r1=1616365&r2=1616366&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test-files/solr/collection1/conf/schema-rest.xml
(original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test-files/solr/collection1/conf/schema-rest.xml
Wed Aug  6 22:28:52 2014
@@ -456,7 +456,7 @@
     <!-- A specialized field for geospatial search. If indexed, this fieldType must not
be multivalued. -->
     <fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/>
 
-    <!-- Field type where stopwords are managed by the REST API -->
+    <!-- Field type where english stopwords are managed by the REST API -->
     <fieldtype name="managed_en" class="solr.TextField">
        <analyzer>
         <tokenizer class="solr.StandardTokenizerFactory"/>
@@ -465,6 +465,15 @@
       </analyzer>
     </fieldtype>
 
+    <!-- Field type where german stopwords are managed by the REST API -->
+    <fieldtype name="managed_de" class="solr.TextField">
+      <analyzer>
+        <tokenizer class="solr.StandardTokenizerFactory"/>
+        <filter class="solr.ManagedStopFilterFactory" managed="german" />
+        <filter class="solr.ManagedSynonymFilterFactory" managed="german" />
+      </analyzer>
+    </fieldtype>
+
  </types>
 
 

Modified: lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/rest/TestRestManager.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/rest/TestRestManager.java?rev=1616366&r1=1616365&r2=1616366&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/rest/TestRestManager.java
(original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/rest/TestRestManager.java
Wed Aug  6 22:28:52 2014
@@ -28,6 +28,8 @@ import org.apache.solr.rest.ManagedResou
 import org.apache.solr.rest.schema.analysis.ManagedWordSetResource;
 import org.junit.Test;
 import org.noggit.JSONUtil;
+import org.restlet.Request;
+import org.restlet.data.Reference;
 
 /**
  * Tests {@link RestManager} functionality, including resource registration,
@@ -248,4 +250,30 @@ public class TestRestManager extends Sol
     RestManager restManager2 = new RestManager();
     restManager2.init(loader, initArgs, storageIO);    
   }
+
+  @Test
+  public void testResolveResourceId () throws Exception {
+    Request testRequest = new Request();
+    Reference rootRef = new Reference("http://solr.apache.org/");
+    testRequest.setRootRef(rootRef);
+
+    Reference resourceRef = new Reference("http://solr.apache.org/schema/analysis/synonyms/de");
+    testRequest.setResourceRef(resourceRef);
+
+    String resourceId = RestManager.ManagedEndpoint.resolveResourceId(testRequest);
+    assertEquals(resourceId, "/schema/analysis/synonyms/de");
+  }
+
+  @Test
+  public void testResolveResourceIdDecodeUrlEntities () throws Exception {
+    Request testRequest = new Request();
+    Reference rootRef = new Reference("http://solr.apache.org/");
+    testRequest.setRootRef(rootRef);
+
+    Reference resourceRef = new Reference("http://solr.apache.org/schema/analysis/synonyms/de/%C3%84ndern");
+    testRequest.setResourceRef(resourceRef);
+
+    String resourceId = RestManager.ManagedEndpoint.resolveResourceId(testRequest);
+    assertEquals(resourceId, "/schema/analysis/synonyms/de/Ändern");
+  }
 }
\ No newline at end of file

Modified: lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedStopFilterFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedStopFilterFactory.java?rev=1616366&r1=1616365&r2=1616366&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedStopFilterFactory.java
(original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedStopFilterFactory.java
Wed Aug  6 22:28:52 2014
@@ -185,4 +185,29 @@ public class TestManagedStopFilterFactor
     // should fail with 404 as foo doesn't exist
     assertJDelete(endpoint + "/foo", "/error/code==404");
   }
+
+  /**
+   * Can we add and remove stopwords with umlauts
+   */
+  @Test
+  public void testCanHandleDecodingAndEncodingForStopwords() throws Exception  {
+    String endpoint = "/schema/analysis/stopwords/german";
+
+    //initially it should not exist
+    assertJQ(endpoint + "/schön", "/error/code==404");
+
+    //now we put a stopword with an umlaut
+    assertJPut(endpoint,
+        JSONUtil.toJSON(Arrays.asList("schön")),
+        "/responseHeader/status==0");
+
+    //let's check if it exists
+    assertJQ(endpoint + "/schön", "/schön=='schön'");
+
+    //now let's remove it
+    assertJDelete(endpoint + "/schön", "/responseHeader/status==0");
+
+    //and of it is unavailable again
+    assertJQ(endpoint + "/schön", "/error/code==404");
+  }
 }

Modified: lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedSynonymFilterFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedSynonymFilterFactory.java?rev=1616366&r1=1616365&r2=1616366&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedSynonymFilterFactory.java
(original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedSynonymFilterFactory.java
Wed Aug  6 22:28:52 2014
@@ -195,4 +195,41 @@ public class TestManagedSynonymFilterFac
     assertJQ(endpoint+"/MB", 
         "/MB==['Megabyte','MiB','megabyte']");    
   }
+
+  /**
+   * Can we add and remove stopwords with umlauts
+   */
+  @Test
+  public void testCanHandleDecodingAndEncodingForSynonyms() throws Exception  {
+    String endpoint = "/schema/analysis/synonyms/german";
+
+    assertJQ(endpoint,
+        "/synonymMappings/initArgs/ignoreCase==false",
+        "/synonymMappings/managedMap=={}");
+
+    // does not exist
+    assertJQ(endpoint+"/fröhlich",
+        "/error/code==404");
+
+    Map<String,List<String>> syns = new HashMap<>();
+
+    // now put a synonym
+    syns.put("fröhlich", Arrays.asList("glücklick"));
+    assertJPut(endpoint,
+        JSONUtil.toJSON(syns),
+        "/responseHeader/status==0");
+
+    // and check if it exists
+    assertJQ(endpoint,
+        "/synonymMappings/managedMap/fröhlich==['glücklick']");
+
+    // verify delete works
+    assertJDelete(endpoint+"/fröhlich",
+        "/responseHeader/status==0");
+
+
+    // was it really deleted?
+    assertJDelete(endpoint+"/fröhlich",
+        "/error/code==404");
+  }
 }



Mime
View raw message