如何从Solr中获取分片中的结果并存储在hashmap数组中

时间:2019-05-16 07:24:25

标签: java solr

我有来自resp.getResponse().get("shards.info")的solr响应数据,如下所示:

 {
xyz1={

     numFound=149040,
     maxScore=1.0,
     shardAddress=http://xyz1,
     time=3
},

xyz2={
     numFound=12414,
     maxScore=1.0,
     shardAddress=http://xyz2,
     time=5
},

xyz3={
     numFound=62175,
     maxScore=1.0,
     shardAddress=http://xyz13,
     time=6
},

xyz4={
     numFound=200572,
     maxScore=1.0,
     shardAddress=http://xyz14,
     time=4
},

xyz5={
     numFound=32853,
     maxScore=1.0,
     shardAddress=http://xyz5,
     time=5
},

xyz6={
     numFound=73443,
     maxScore=1.0,
     shardAddress=http://xyz6,
     time=5
}
 }
        for (SolrDocument solrDocument:resp.getResponse().get("shards.info")) 
        { 
            documentsList.add(solrDocument);
        }


 but found this error "Can only iterate over an array or an instance of java.lang.Iterable"
How to pass those values into documentsList_shards please help me

1 个答案:

答案 0 :(得分:0)

如果对“欢迎您”有所改进,希望对您有所帮助

    NamedList<Object> report = (NamedList<Object>)resp.getResponse().get("shards.info");
    Iterator<Map.Entry<String, Object>> coreIterator = report.iterator();
    HashMap<String, String> hm = new HashMap<String, String>(); 
    while(coreIterator.hasNext())
    {
        Map.Entry<String, Object> core = coreIterator.next();
        String core_name=(core.getKey().toString()).replace("abcc","");
        NamedList<Object> report_in = (NamedList<Object>)core.getValue();
        Iterator<Map.Entry<String, Object>> coreIterator_in = report_in.iterator();
        while(coreIterator_in.hasNext()){
            Map.Entry<String, Object> core_in = coreIterator_in.next();
            if(core_in.getKey().equals("numFound"))
            {
                String numFound=core_in.getValue().toString();
                hm.put(core_name, numFound); 
            }
        }
    }
相关问题