(PECL solr >= 2.3.0)
SolrInputDocument::addChildDocument — 添加子文档以进行块索引
child
一个 SolrInputDocument 对象。
不返回值。
示例 #1 SolrInputDocument::addChildDocument() 示例
<?php
include "bootstrap.php";
$options = array
(
'hostname' => SOLR_SERVER_HOSTNAME,
'login' => SOLR_SERVER_USERNAME,
'password' => SOLR_SERVER_PASSWORD,
'port' => SOLR_SERVER_PORT,
'path' => SOLR_SERVER_STORE_PATH,
);
$client = new SolrClient($options);
$product = new SolrInputDocument();
$product->addField('id', 'P-BLACK');
$product->addField('cat', 'tshirt');
$product->addField('cat', 'polo');
$product->addField('content_type', 'product');
$small = new SolrInputDocument();
$small->addField('id', 'TS-BLK-S');
$small->addField('content_type', 'sku');
$small->addField('size', 'S');
$small->addField('inventory', 100);
$medium = new SolrInputDocument();
$medium->addField('id', 'TS-BLK-M');
$medium->addField('content_type', 'sku');
$medium->addField('size', 'M');
$medium->addField('inventory', 200);
$large = new SolrInputDocument();
$large->addField('id', 'TS-BLK-L');
$large->addField('content_type', 'sku');
$large->addField('size', 'L');
$large->addField('inventory', 300);
// 添加子文档
$product->addChildDocument($small);
$product->addChildDocument($medium);
$product->addChildDocument($large);
// 将产品文档块添加到索引中
$updateResponse = $client->addDocument(
$product,
true, // 如果文档存在,则覆盖
10000 // 在 10 秒内提交
);
print_r($updateResponse->getResponse());
上面的示例将输出类似于
SolrObject Object ( [responseHeader] => SolrObject Object ( [status] => 0 [QTime] => 5 ) )