dty63504 2015-04-08 12:30
浏览 95
已采纳

如何使用Solr Search获取唯一的disintct值

i'm new to solr search.I want to get disinct values of fields using solr. I'm using &rows=0&facet=on&facet.field=fieldname&wt=json

Output:

facet_fields":{"packagename":["bangalore",2,"hyerabadd",2,"australia",3]

This is my code for decode above output:

<?php
header("Content-type:text/json");

$data=file_get_contents("http://localhost:8984/solr/collection1/select?q=*:*&rows=0&facet=on&facet.field=fieldname&wt=json");

$res=json_decode($data);

foreach($res->facet_counts->facet_fields as $doc){
    foreach($doc as $value){
      echo $value; 
    }
}
?>

Output after decode:

bangalore
2
hyderabad
2
australia
3

but,here i dont't want to display those numbers(min count).

  • 写回答

1条回答 默认 最新

  • doubanduo7620 2015-04-08 13:24
    关注

    Look here

    You can specify how the result should be returned in the JSON. Default is how it is shown above in your question. With json.nl=arrarr added to your query it will look like this

    facet_fields":{ "packagename":[["bangalore",2],["hyerabadd",2],["australia",3]]
    

    and it should be easier to distinguish between name and count

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题