2011-07-08 55 views

回答

4

当您想要更新文档时,只需使用同一组必填字段调用函数“addDocument”即可。 Solr将在内部更新文档。

Solr不支持更新文档中的单个字段,如果多数民众赞成你正在寻找。来源:SOLR-139

希望它有帮助!

+0

是的,我明白这一点,但我还是谢谢你! – einstein

2

这是SOLR 4.0新 -

正如我在Update specific field on SOLR index说,它现在可以更新的字段。这就是我的回答:

请参考this document有关“部分文档更新”功能在Solr的4.0

Solr的4.0,处于测试阶段在此张贴的时间,将是最终的,制法准备在大约一个月内,根据Road Map

此功能可以更新字段,甚至可以将值添加到multiValued字段。

毛里西奥在2010年的回答是正确的,但今天就是这样。

2

这是我要做的事:

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(); 
// Find old Document 
$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(); 
}