通过PHP cURL将文档添加到Apache Solr [英] Add document to Apache Solr via PHP cURL
本文介绍了通过PHP cURL将文档添加到Apache Solr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道我做错了什么。记录未添加。
I don't know what I have done wrong. The record does not get added.
这是我的代码:
$ch = curl_init("http://127.0.0.1:8983/solr/collection1/update/json?commit=true");
$data = array(
"add" => array( "doc" => array(
"id" => "HW132",
"name" => "Hello World"
))
);
$data_string = json_encode($data);
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, $data_string);
$response = curl_exec($ch);
这是我从Solr得到的答复:
And here is the response that I get from Solr:
{"responseHeader":{"status":0,"QTime":4}}
推荐答案
显然,我需要让Apache Solr提交文档。它不会自动提交文档,或者我可能不知道如何配置它才能自动提交。以下是工作示例。希望对那些有相同问题的人有所帮助。
Apparently, I need to ask Apache Solr to commit the document. It does not auto commit the document or maybe I don't know how to config for it to auto commit. The following is the working example. Hope it will help to those who has the same problem.
$ch = curl_init("http://127.0.0.1:8983/solr/collection1/update?wt=json");
$data = array(
"add" => array(
"doc" => array(
"id" => "HW2212",
"title" => "Hello World 2"
),
"commitWithin" => 1000,
),
);
$data_string = json_encode($data);
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, $data_string);
$response = curl_exec($ch);
这篇关于通过PHP cURL将文档添加到Apache Solr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文