首页 > 代码库 > PHP添加、更新solr索引

PHP添加、更新solr索引

 1 <?php 2 $options = array 3 ( 4     ‘hostname‘ => ‘localhost‘, 5     ‘port‘     => ‘8080‘, 6     ‘path‘=>‘solr/help_category‘, 7     ‘wt‘=>‘json‘ 8 ); 9 $client = new SolrClient($options); 10 11   12 $doc = new SolrInputDocument();13 14 $doc->addField(‘id‘, 501000);15 $doc->addField(‘title‘, ‘Hello Wolrd‘);16 // $fields=$doc->getField (‘id‘);17 // var_dump($fields);exit;18 $response = $client->addDocument($doc);19 var_dump($response);20 $client->commit();21 ?>

当索引文档中主键id值存在时,会更新原文档,不存在则会添加文档

PHP添加、更新solr索引