【发布时间】:2015-12-01 14:31:59
【问题描述】:
在我的服务器上设置 solr 3.6 之前,我开始使用 Bitnami Solr Stack 5.0。
这是我用来索引数据的方式:
$ch = curl_init(SOLR_HOST . SOLR_CORE_PRODUCTS . "/update?wt=json&commitWithin=4000&debugQuery=true&overwrite=&true&commit=true");
$json = array(array("Field" => "value", "Field2" => "value2"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $js);
$response = curl_exec($ch);
现在,让我们关注 Solr 的人
Solr 3.1 示例
Solr 3.2 是第一个支持 JSONObject 数组语法的版本,因此在 Solr 3.1 中需要使用重复的名称(“add”标签)来一次添加多个文档。在 JSON 中具有重复名称是合法的。示例:
curl http://localhost:8983/solr/update/json -H 'Content-type:application/json' -d '
{
"add": {"doc": {"id" : "TestDoc1", "title" : "test1"} },
"add": {"doc": {"id" : "TestDoc2", "title" : "another test"} }
}'
我明白了:
$ch = curl_init(SOLR_HOST . SOLR_CORE_PRODUCTS . "/update?wt=json&commitWithin=4000&debugQuery=true&overwrite=&true&commit=true");
$json = array("add: " => array("doc:" =>array("Field" => "value", "Field2" => "value2")));
$js = json_encode($json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $js);
$response = curl_exec($ch);
会做这项工作。 $js 具有以下价值:
{"add: ":{"doc:":{"Field":"value","Field2":"value2"}}}
错误是:
消息序言中出现意外字符“{”(代码 123); [row,col {unknown-source}] 处的预期“
有什么想法吗?
【问题讨论】: