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

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

报告相同问题?

悬赏问题

  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果