SOLR-7508: SolrParams.toMultiMap() does not handle arrays

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1679494 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Noble Paul 2015-05-15 05:51:29 +00:00
parent d0251d9b10
commit 0ba7aca779
3 changed files with 40 additions and 2 deletions

View File

@ -666,6 +666,8 @@ Bug Fixes
* SOLR-7286: Using HDFS's FileSystem.newInstance does not guarantee a new instance.
(Mark Miller)
* SOLR-7508: SolrParams.toMultiMap() does not handle arrays (Thomas Scheffler , Noble Paul)
Optimizations
----------------------

View File

@ -313,8 +313,12 @@ public abstract class SolrParams implements Serializable {
HashMap<String,String[]> map = new HashMap<>();
for (int i=0; i<params.size(); i++) {
String name = params.getName(i);
String val = params.getVal(i).toString();
MultiMapSolrParams.addParam(name,val,map);
Object val = params.getVal(i);
if (val instanceof String[]) {
MultiMapSolrParams.addParam(name, (String[]) val, map);
} else {
MultiMapSolrParams.addParam(name, val.toString(), map);
}
}
return map;
}

View File

@ -17,6 +17,7 @@
package org.apache.solr.common.params;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
@ -25,6 +26,7 @@ import java.util.Iterator;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.util.NamedList;
/**
*/
@ -80,6 +82,36 @@ public class SolrParamTest extends LuceneTestCase {
}
public void testMultiValues() {
NamedList nl = new NamedList();
nl.add("x", "X1");
nl.add("x", "X2");
nl.add("x", new String[]{"X3", "X4"});
Map<String, String[]> m = SolrParams.toMultiMap(nl);
String[] r = m.get("x");
assertTrue(Arrays.asList(r).containsAll(Arrays.asList(new String[]{"X1", "X2", "X3", "X4"})));
}
public void testGetAll() {
ModifiableSolrParams params = new ModifiableSolrParams();
params.add("x", "X1");
params.add("x", "X2");
params.add("y", "Y");
Map<String, Object> m = params.getAll(null, "x", "y");
String[] x = (String[]) m.get("x");
assertEquals(2, x.length);
assertEquals("X1", x[0]);
assertEquals("X2", x[1]);
assertEquals("Y", m.get("y"));
try {
params.required().getAll(null, "z");
fail("Error expected");
} catch (SolrException e) {
assertEquals(e.code(), SolrException.ErrorCode.BAD_REQUEST.code);
}
}
public void testModParamAddParams() {
ModifiableSolrParams aaa = new ModifiableSolrParams();