gpt4 book ai didi

java - 如何从 solr 获取分片中的结果并将其存储在 hashmap 数组中

转载 作者:行者123 更新时间:2023-12-02 05:36:24 24 4
gpt4 key购买 nike

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

 {
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

最佳答案

希望对大家有所帮助,如果有改进请不客气

    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);
}
}
}

关于java - 如何从 solr 获取分片中的结果并将其存储在 hashmap 数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56162983/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com