【发布时间】: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?
【问题讨论】: