【问题标题】:count distinct in solr without command line cURL在没有命令行 cURL 的情况下在 solr 中计数不同
【发布时间】:2016-08-18 15:41:05
【问题描述】:

对于如何从他们的网站http://yonik.com/solr-count-distinct/ 以及从这个 SO 答案:How to select distinct field values using Solr?

我的问题是我不明白如何将此 cURL 语法翻译成 PHP,这就是我正在编码的内容。

这段代码发生了什么的角度来看,官方示例似乎很容易理解:

$ curl http://localhost:8983/solr/techproducts/query -d '
q=*:*&
json.facet={
  x : "unique(manu_exact)"    // manu_exact is the manufacturer indexed as a single string
}'

但是,我只熟悉使用 PHP 向我的服务器提交 solr 查询的两种方法。第一种,使用直接 URL:

$url = "localhost:8983/solr/asdf/select?q=*:*";
$Q = curl_init();      
curl_setopt($Q, CURLOPT_RETURNTRANSFER, true);        
curl_setopt($Q, CURLOPT_URL, $url);
$rawData = curl_exec($Q);
$data =  json_decode($rawData,true);

或通过发布值:

$url     = "localhost:8983/solr/asdf/select";
$solr_q  = "q=date_range:[2016+TO+*]&fq=title:manager&wt=json&indent=true";

$ch      = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $solr_q);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);        
curl_setopt($ch, CURLOPT_URL, $url);
$rawData = curl_exec($ch);
$json = json_decode($rawData,true);

我正在运行 solr 5.4.1,所以我知道我有能力做 json 方面,但我不知道如何使用命令行 curl 在官方示例之外发出请求。如何以与我目前在 PHP 中使用 solr 相同的方式使用此 json.facet

【问题讨论】:

    标签: php curl solr


    【解决方案1】:

    与往常一样 - 在您在 SO 上发帖后,您就会找到答案。如果有人仍然可以对我这样做的更好方式有所了解,我将非常感激 - 但从技术上讲,这可以作为直接 URL:

    http://localhost:8983/solr/asdf/select?q=*:*&json.facet.x="unique(field)"&wt=json&indent=true&rows=0
    

    或使用我在 OP 中使用的语法:

    ...
    $url    = "http://localhost:8983/solr/asdf/select";
      $post   = "q=*:*&json.facet.x=\"unique(field)\"&rows=0&wt=json&indent=true";
    ...
    

    我缺少的是:

    1. 我必须命名 json facet,(&json.facet.x= 而不是 &json.facet= 并且需要将 { } 字符替换为引号 " " 以便查询作为 URL 或 POST 请求工作.

    我真的希望这对某人有所帮助,因为它已经让我沮丧了大约一个月......

    【讨论】:

      猜你喜欢
      • 2013-01-31
      • 2012-07-15
      • 2021-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多