lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From no...@apache.org
Subject svn commit: r1655542 - in /lucene/dev/branches/branch_5x: ./ solr/ solr/core/ solr/core/src/java/org/apache/solr/core/ solr/core/src/test/org/apache/solr/core/ solr/core/src/test/org/apache/solr/handler/ solr/solrj/ solr/solrj/src/java/org/apache/solr/...
Date Thu, 29 Jan 2015 07:44:07 GMT
Author: noble
Date: Thu Jan 29 07:44:07 2015
New Revision: 1655542

URL: http://svn.apache.org/r1655542
Log:
SOLR-7059: Using paramset with multi-valued keys leads to a 500. SolrParams need an aray instead
of a list 

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/solr/   (props changed)
    lucene/dev/branches/branch_5x/solr/core/   (props changed)
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/core/RequestParams.java
    lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.java
    lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerCloud.java
    lucene/dev/branches/branch_5x/solr/solrj/   (props changed)
    lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/common/params/MapSolrParams.java

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/core/RequestParams.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/core/RequestParams.java?rev=1655542&r1=1655541&r2=1655542&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/core/RequestParams.java
(original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/core/RequestParams.java
Thu Jan 29 07:44:07 2015
@@ -23,6 +23,7 @@ import java.io.InputStreamReader;
 import java.nio.charset.StandardCharsets;
 import java.util.Collections;
 import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.solr.cloud.ZkSolrResourceLoader;
@@ -58,7 +59,7 @@ public class RequestParams implements Ma
         Map.Entry e = (Map.Entry) o;
         if (e.getValue() instanceof Map) {
           Map value = (Map) e.getValue();
-          Map copy = new LinkedHashMap<>(value);
+          Map copy = getMapCopy(value);
           Map meta = (Map) copy.remove("");
           this.paramsets.put((String) e.getKey(), new VersionedParams(Collections.unmodifiableMap(copy)
,meta));
         }
@@ -67,6 +68,32 @@ public class RequestParams implements Ma
     this.znodeVersion = znodeVersion;
   }
 
+  private static Map getMapCopy(Map value) {
+    Map copy = new LinkedHashMap<>();
+    for (Object o1 : value.entrySet()) {
+      Map.Entry entry = (Map.Entry) o1;
+      if("".equals( entry.getKey())){
+        copy.put(entry.getKey(),entry.getValue());
+        continue;
+      }
+      if (entry.getValue() != null) {
+        if (entry.getValue() instanceof List) {
+          List l = (List) entry.getValue();
+          String[] sarr = new String[l.size()];
+          for (int i = 0; i < l.size(); i++) {
+            if( l.get(i) != null)  sarr[i]= String.valueOf(l.get(i));
+          }
+          copy.put(entry.getKey(), sarr);
+        } else {
+          copy.put(entry.getKey(), String.valueOf(entry.getValue()));
+        }
+      } else {
+        copy.put(entry.getKey(), entry.getValue());
+      }
+    }
+    return copy;
+  }
+
   public VersionedParams getParams(String name){
     return paramsets.get(name);
   }
@@ -77,7 +104,7 @@ public class RequestParams implements Ma
 
   @Override
   public Map<String, Object> toMap() {
-    return getMapWithVersion(data,znodeVersion);
+    return getMapWithVersion(data, znodeVersion);
   }
 
   public static Map<String, Object> getMapWithVersion(Map<String, Object> data,
int znodeVersion) {

Modified: lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.java?rev=1655542&r1=1655541&r2=1655542&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.java
(original)
+++ lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.java
Thu Jan 29 07:44:07 2015
@@ -22,6 +22,7 @@ import com.google.common.collect.Immutab
 import org.apache.commons.io.FileUtils;
 import org.apache.solr.SolrTestCaseJ4;
 import org.apache.solr.client.solrj.impl.CloudSolrClient;
+import org.apache.solr.handler.TestSolrConfigHandlerCloud;
 import org.apache.solr.handler.TestSolrConfigHandlerConcurrent;
 import org.apache.solr.util.RestTestBase;
 import org.apache.solr.util.RestTestHarness;
@@ -47,8 +48,10 @@ import java.util.SortedMap;
 import java.util.TreeMap;
 import java.util.concurrent.TimeUnit;
 
+import static java.util.Arrays.asList;
 import static org.apache.solr.core.ConfigOverlay.getObjectByPath;
 import static org.apache.solr.handler.TestBlobHandler.getAsString;
+import static org.apache.solr.handler.TestSolrConfigHandlerCloud.compareValues;
 
 public class TestSolrConfigHandler extends RestTestBase {
   public static final Logger log = LoggerFactory.getLogger(TestSolrConfigHandler.class);
@@ -341,7 +344,8 @@ public class TestSolrConfigHandler exten
     payload = " {\n" +
         "  'set' : {'y':{\n" +
         "                'c':'CY val',\n" +
-        "                'b': 'BY val'}\n" +
+        "                'b': 'BY val', " +
+        "                'd': ['val 1', 'val 2']}\n" +
         "             }\n" +
         "  }";
 
@@ -384,6 +388,15 @@ public class TestSolrConfigHandler exten
         null,
         5);
 
+    TestSolrConfigHandler.testForResponseElement(
+        harness,
+        null,
+        "/dump1?wt=json&useParams=y",
+        null,
+        Arrays.asList("params", "d"),
+        Arrays.asList("val 1", "val 2") ,
+        5);
+
     payload = " {\n" +
         "  'update' : {'y': {\n" +
         "                'c':'CY val modified',\n" +

Modified: lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerCloud.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerCloud.java?rev=1655542&r1=1655541&r2=1655542&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerCloud.java
(original)
+++ lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerCloud.java
Thu Jan 29 07:44:07 2015
@@ -20,10 +20,12 @@ package org.apache.solr.handler;
 
 import java.text.MessageFormat;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 
+import org.apache.solr.SolrTestCaseJ4;
 import org.apache.solr.client.solrj.SolrClient;
 import org.apache.solr.client.solrj.impl.HttpSolrClient;
 import org.apache.solr.cloud.AbstractFullDistribZkTestBase;
@@ -174,7 +176,9 @@ public class TestSolrConfigHandlerCloud
     payload = " {\n" +
         "  'set' : {'y':{\n" +
         "                'c':'CY val',\n" +
-        "                'b': 'BY val'}\n" +
+        "                'b': 'BY val', " +
+        "                'i': 20, " +
+        "                'd': ['val 1', 'val 2']}\n" +
         "             }\n" +
         "  }";
 
@@ -189,6 +193,8 @@ public class TestSolrConfigHandlerCloud
         asList("response", "params", "y", "c"),
         "CY val",
         10);
+    compareValues(result, 20l, asList("response", "params", "y", "i"));
+
 
     result = TestSolrConfigHandler.testForResponseElement(null,
         urls.get(random().nextInt(urls.size())),
@@ -199,6 +205,8 @@ public class TestSolrConfigHandlerCloud
         5);
     compareValues(result, "BY val", asList("params", "b"));
     compareValues(result, null, asList("params", "a"));
+    compareValues(result, Arrays.asList("val 1", "val 2")  , asList("params", "d"));
+    compareValues(result, "20"  , asList("params", "i"));
     payload = " {\n" +
         "  'update' : {'y': {\n" +
         "                'c':'CY val modified',\n" +
@@ -256,7 +264,7 @@ public class TestSolrConfigHandlerCloud
 
   }
 
-  public static void compareValues(Map result, String expected, List<String> jsonPath)
{
+  public static void compareValues(Map result, Object expected, List<String> jsonPath)
{
     assertTrue(MessageFormat.format("Could not get expected value  {0} for path {1} full
output {2}", expected, jsonPath, getAsString(result)),
         Objects.equals(expected, ConfigOverlay.getObjectByPath(result, false, jsonPath)));
   }

Modified: lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/common/params/MapSolrParams.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/common/params/MapSolrParams.java?rev=1655542&r1=1655541&r2=1655542&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/common/params/MapSolrParams.java
(original)
+++ lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/common/params/MapSolrParams.java
Thu Jan 29 07:44:07 2015
@@ -19,6 +19,7 @@ package org.apache.solr.common.params;
 
 import org.apache.solr.common.util.StrUtils;
 
+import java.util.Arrays;
 import java.util.Iterator;
 import java.util.Map;
 import java.io.IOException;
@@ -35,13 +36,22 @@ public class MapSolrParams extends SolrP
 
   @Override
   public String get(String name) {
-    return map.get(name);
+    Object  o = map.get(name);
+    if(o == null) return null;
+    if (o instanceof String) return  (String) o;
+    if (o instanceof String[]) {
+      String[] strings = (String[]) o;
+      if(strings.length == 0) return null;
+      return strings[0];
+    }
+    return String.valueOf(o);
   }
 
   @Override
   public String[] getParams(String name) {
-    String val = map.get(name);
-    return val==null ? null : new String[]{val};
+    Object val = map.get(name);
+    if (val instanceof String[]) return (String[]) val;
+    return val==null ? null : new String[]{String.valueOf(val)};
   }
 
   @Override
@@ -59,13 +69,16 @@ public class MapSolrParams extends SolrP
 
       for (Map.Entry<String,String> entry : map.entrySet()) {
         String key = entry.getKey();
-        String val = entry.getValue();
-
+        Object val = entry.getValue();
+        if (val instanceof String[]) {
+          String[] strings = (String[]) val;
+          val =  StrUtils.join(Arrays.asList(strings),',');
+        }
         if (!first) sb.append('&');
         first=false;
         sb.append(key);
         sb.append('=');
-        StrUtils.partialURLEncodeVal(sb, val==null ? "" : val);
+        StrUtils.partialURLEncodeVal(sb, val==null ? "" : String.valueOf(val));
       }
     }
     catch (IOException e) {throw new RuntimeException(e);}  // can't happen



Mime
View raw message