Uploaded image for project: 'Solr'
  1. Solr
  2. SOLR-1666

SolrParams conversion to NamedList and back to SolrParams misses the Arrays with more than one value

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Implemented
    • 1.3, 1.4
    • None
    • search
    • None

    Description

      When a parameter in a SolrParams instance is an Array that has more than one element, the method SolrParams.toNamedList() generates a NamedList<Object> correctly, but when the method SolrParams.toSolrParams() is invoked with that NamedList instance, the resultant SolrParams instance has that parameter as a String, wich is the result of the String[].toString() method.

      TestCase:

      public class TestDismaxQParserPlugin extends DisMaxQParserPlugin {
      	private Log log = LogFactory.getLog(this.getClass());
      	public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
      
      		// TestCase with the param facet.field
      		if(params.getParams(FacetParams.FACET_FIELD) != null) {
      			// Original Values
      			log.debug("FACET.FIELD Param - Before");
      			String[] facetFieldBefore = params.getParams(FacetParams.FACET_FIELD);
      			log.debug("toString():"+facetFieldBefore.toString());
      			log.debug("length:"+facetFieldBefore.length);
      			log.debug("Elements:");
      			for(String value : facetFieldBefore) 
      				log.debug("[class "+value.getClass().getName()+"] "+value);
      			
      			// Transforming
      			NamedList<Object> paramsList = params.toNamedList();
      			params = SolrParams.toSolrParams(paramsList);
      
      			// Result Values
      			log.debug("FACET.FIELD Param - After");
      			String[] facetFieldAfter = params.getParams(FacetParams.FACET_FIELD);
      			log.debug("toString():"+facetFieldAfter.toString());
      			log.debug("length:"+facetFieldAfter.length);
      			log.debug("Elements:");
      			for(String value : facetFieldAfter) 
      				log.debug("[class "+value.getClass().getName()+"] "+value);
      		} else {
      			log.debug("FACET.FIELD NOT SPECIFIED");
      		}
      		return super.createParser(qstr, localParams, params, req);
      	}
      }
      

      Editing the solrconfig.xml file for this QueryParser to be used and using an URL like "http://host:port/path/select?q=something&facet=true&facet.field=subject&facet.field=date" the output is (only the interesting lines):

      FINA: FACET.FIELD Param - Before
      FINA: toString():[Ljava.lang.String;@c96ad7c
      FINA: length:2
      FINA: Elements:
      FINA: [class java.lang.String] subject
      FINA: [class java.lang.String] date
      FINA: FACET.FIELD Param - After
      FINA: toString():[Ljava.lang.String;@44775121
      FINA: length:1
      FINA: Elements:
      FINA: [class java.lang.String] [Ljava.lang.String;@c96ad7c

      Attachments

        1. SOLR-1666.patch
          3 kB
          Dan Brown

        Issue Links

          Activity

            People

              hossman Chris M. Hostetter
              oviedonestor Nestor Oviedo
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: