在我的服務器上設置solr 3.6之前,我開始使用Bitnami Solr Stack 5.0。Solr 5.3更新查詢VS Solr 3.6(使用php curl和json)
這是我如何索引用我的數據:
$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"} }
}'
我throught說:
$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)在序言;預計'<'at [row,col {unknown-source}]:[1,1]
任何想法?