You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Hana <ha...@k-int.com> on 2009/01/23 16:33:08 UTC

Method toMultiMap(NamedList params) in SolrParams

Hi,

I'm getting confused about the method Map<String,String[]>
toMultiMap(NamedList params) in SolrParams class.
When some of your parameter is instanceof String[] it's converted to to
String using the toString() method, which seems
to me to be wrong. It is probably assuming, that the values in NamedList are
all String, but when you look at the method
toNamedList() it's clearly adding String[] in case that the parameter has
more than one value.
So my question is, wheater it is a bug or I'm getting something wrong.


public static Map<String,String[]> toMultiMap(NamedList params) {
    HashMap<String,String[]> map = new HashMap<String,String[]>();
    for (int i=0; i<params.size(); i++) {
      String name = params.getName(i);
      String val = params.getVal(i).toString();
      MultiMapSolrParams.addParam(name,val,map);
    }
    return map;
  }


public NamedList toNamedList() {
    final SimpleOrderedMap result = new SimpleOrderedMap();
	   
    for(Iterator<String> it=getParameterNamesIterator(); it.hasNext(); ) {
      final String name = it.next();
      final String [] values = getParams(name);
      if(values.length==1) {
           result.add(name,values[0]);
      } else {
          // currently no reason not to use the same array
          result.add(name,values);
      }
    }
    return result;
  }


Cheers

Hana
-- 
View this message in context: http://www.nabble.com/Method-toMultiMap%28NamedList-params%29-in-SolrParams-tp21626588p21626588.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: Method toMultiMap(NamedList params) in SolrParams

Posted by Chris Hostetter <ho...@fucit.org>.
: I'm getting confused about the method Map<String,String[]>
: toMultiMap(NamedList params) in SolrParams class.

toMultiMap probably shouldn't have ever been made public -- it' really 
only ment to be use by toSolrParams (it's refactored out to make the code 
easier to read)

: When some of your parameter is instanceof String[] it's converted to to
: String using the toString() method, which seems
: to me to be wrong. It is probably assuming, that the values in NamedList are
: all String, but when you look at the method

It's not assuming that the NamedList only contains Strings -- it's 
assuming that since it needs to produce a String[] then every object in 
the NamedList should be toString()ed to get a String.  in your case since 
the object is already String[] that seems silly -- but you have to keep in 
mind the whole point is to build a String[] out of *multiple* objects 
(that have the same key in the NamedList) ... so if your NamedLIst 
contained two String[]'s with the same key, what would you expect it to do 
if the behavior was different (union the two arrays?)





-Hoss