gpt4 book ai didi

php - 通过 PHP cURL 将文档添加到 Apache Solr

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:05:18 25 4
gpt4 key购买 nike

我不知道我做错了什么。记录没有被添加。

这是我的代码:

$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 得到的响应:

{"responseHeader":{"status":0,"QTime":4}}

最佳答案

显然,我需要请求 Apache Solr 提交文档。它不会自动提交文档,或者我可能不知道如何配置它以自动提交。以下是工作示例。希望对遇到同样问题的人有所帮助。

$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 - 通过 PHP cURL 将文档添加到 Apache Solr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24174999/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com