On 05/27/2014 04:21 PM, Steve Rowe wrote:
Shawn’s code shows that SolrJ parses the JSON for you into NamedList 
(response.getResponse()). - Steve
Thank you for pointing it out.

It wasn't apparent what get(key) returns since the method signature
of getResponse() merely tells it would return a NamedList<Object>.
After running a test code under debugger, I found out, for key="fields",
the returned object is of ArrayList<SimpleOrderedMap<NameValuePair>>.
This is what I came up with:

    private static final String url = "http://localhost:8983/solr/hlbase";;
    private static final SolrServer server = new HttpSolrServer(url);
   ...
    SolrQuery query = new SolrQuery();
    query.setRequestHandler("/schema/fields");
    QueryResponse response = server.query(query);

List<SimpleOrderedMap<NameValuePair>> fields = (ArrayList<SimpleOrderedMap<NameValuePair>>) response.getResponse().get("fields");
    for(SimpleOrderedMap<NameValuePair> fmap : fields) {
      System.out.println(fmap.get("name"));
    }


Kuro

Reply via email to