Search code examples
javasolrj

Get the value from java object


Using the below code

Object str = response.getHeader().get("parms");

I get the flowing response

params={q=catlevel0:sales (1105),facet.field=catlevel3,facet.mincount=1,fq=catlevel2:and (35),facet=true,wt=xml,version=2.2}

How can i get value for "q", "facet.field", "fq"

Please help..


Solution

  • using the following code

    NamedList<Object> results = (NamedList<Object>) response.getHeader().get("params");
    
    for (int i = 0; i < results.size(); i++) {
        System.out.println("restuls: " + i + " " + results.getName(i) + " : " + results.getVal(i));
    }
    

    you can get all your params. If you want explicitly q, facet.field, fq you can compare results.getName(i) with q, facet.field, fq ie with q

    for (int i = 0; i < results.size(); i++) {
    
       if ("q".equals(results.getName(i))){
          System.out.println(results.getVal(i));
        }
    }
    

    Hope this helps