PHP 如何在 Apache Solr 中更新文档

In PHP how to update a document in Apache Solr

我正在使用 PHP Apache Solr Search Engine Extensions 并且正在尝试更新 Apache Solr 中的现有索引。我知道 Solr 中没有实际更新,所以我要做的是以下 (update_by_id):

    include "bootstrap.php";
    $options = array
        (
        'hostname' => SOLR_SERVER_HOSTNAME,
        'login' => SOLR_SERVER_USERNAME,
        'password' => SOLR_SERVER_PASSWORD,
        'port' => SOLR_SERVER_PORT,
    );

    $client = new SolrClient($options);

    $query = new SolrQuery();

    $query->setQuery('id:1000012');

    $query->setStart(0);

    $query->setRows(1);

//        $query->addField('cat')->addField('features')->addField('id')->addField('timestamp');

    $query_response = $client->query($query);

    $response = $query_response->getResponse();

    if ($response->response->numFound) {
        $second_doc = new SolrInputDocument();
        $second_doc->addField('cat', 'TESTCAT');
        $second_doc->merge($response, true);
        $updateResponse = $client->addDocument($second_doc);
        $client->commit();
    }

但我收到以下错误:

Catchable fatal error: Argument 1 passed to SolrInputDocument::merge() must be an instance of SolrInputDocument, instance of SolrObject given in /var/www/html/solr-test.dev/update.php on line 44

如果这不是正确的方法,那是什么?

Solr 信息:

Solr Specification Version: 3.6.2.2014.11.01.05.22.12
Solr Implementation Version: 3.6.2 debian - buildd - 2014-11-01 05:22:12
Lucene Specification Version: 3.6.2
Lucene Implementation Version: 3.6.2 debian - buildd - 2014-11-01 05:19:47

在@Random 的一些指导下,我终于让它工作了。这就是我设法做到的:

include "bootstrap.php";
$options = array
(
    'hostname' => SOLR_SERVER_HOSTNAME,
    'login' => SOLR_SERVER_USERNAME,
    'password' => SOLR_SERVER_PASSWORD,
    'port' => SOLR_SERVER_PORT,
);
$client = new SolrClient($options);
$query = new SolrQuery();
$query->setQuery('id:1000012');
$query->setStart(0);
$query->setRows(1);
$query_response = $client->query($query);
// I had to set the parsemode to PARSE_SOLR_DOC
$query_response->setParseMode(SolrQueryResponse::PARSE_SOLR_DOC);
$response = $query_response->getResponse();
$doc = new SolrInputDocument();
// used the getInputDocument() to get the old document from the query
$doc = $response->response->docs[0]->getInputDocument();
if ($response->response->numFound) {
    $second_doc = new SolrInputDocument();
    $second_doc->addField('cat', "TESTCAT");
// Notice I removed the second parameter from the merge()
    $second_doc->merge($doc);
    $updateResponse = $client->addDocument($second_doc);
    $client->commit();
}