Php solr中计数不带命令行cURL
对于如何从他们的网站上获得solr中的唯一计数,有一个非常好的答案,根据这个答案: 我的问题是,我不明白如何将这个cURL语法翻译成PHP,这就是我正在编写的代码 从代码的角度来看,官方示例似乎很容易理解:Php solr中计数不带命令行cURL,php,curl,solr,Php,Curl,Solr,对于如何从他们的网站上获得solr中的唯一计数,有一个非常好的答案,根据这个答案: 我的问题是,我不明白如何将这个cURL语法翻译成PHP,这就是我正在编写的代码 从代码的角度来看,官方示例似乎很容易理解: $ curl http://localhost:8983/solr/techproducts/query -d ' q=*:*& json.facet={ x : "unique(manu_exact)" // manu_exact is the manufacturer
$ 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);
http://localhost:8983/solr/asdf/select?q=*:*&json.facet.x="unique(field)"&wt=json&indent=true&rows=0
或通过发布价值观:
$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);
我正在运行Solr5.4.1,因此我知道我有能力处理json方面,但我不知道如何使用命令行curl在官方示例之外发出请求。我如何使用这个
json.facet
,就像我目前在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);
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";
...
我缺少的是:
&json.facet.x=
而不是&json.facet=
,{}
字符需要替换为引号”
,以便将查询用作URL或POST请求