在 solr 查询中执行 groupby 后,我得到以下格式的响应。我正在使用 solr 3.5 版
"grouped":{
"channel_id":{
"matches":48,
"ngroups":26,
"groups":[{
"groupValue":"204",
"doclist":{"numFound":1,"start":0,"docs":[
{
"channel_name":"ZeeTv",
"channel_num":4,
"title":"The Name",
"channel_id":"204"
}},
{
"groupValue":"166",
"doclist":{"numFound":2,"start":0,"docs":[
{
"channel_name":"Sony",
"channel_num":2,
"title":"The Name",
"channel_id":"166",
{
"channel_name":"Sony",
"channel_num":2,
"title":"The Puzzle",
"channel_id":"166"
}}]}}
我通过以下方式在数组中获取响应:
for(var chl in data.grouped.channel_id.groups) {
config['playlist'].push(data.grouped.channel_id.groups[chl]['doclist']['docs']);
}
这样就形成了每一个的单独阵列groupValue
。数组的结构是:
"0"=>{"0"=>"value"},"1"=>{"0"=>"result1","1"=>"result2"}
但是我想groupValue
在创建数组时将键名(即“0”、“1”)更改为响应中的键名,以便我可以从数组config['playlist']['166']
中检查所有节目channel_id
。可以做到这一点,如果可以的话怎么做。我期待以下内容:
"204"=>{"0"=>"value"},"166"=>{"0"=>"result1","1"=>"result2"}
此外,如果可能的话,可以进行 solr 查询,使得channel_num
响应中的响应按升序排列,即 channel_num 2 的第一个结果,然后是 4。我已经完成了groupby:channel_id