(PECL solr >= 2.3.0)
SolrInputDocument::addChildDocuments — 添加一组子文档
docs
一个 array,包含 SolrInputDocument 对象。
没有返回值。
范例 #1 SolrInputDocument::addChildDocuments() 范例
<?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);
// 添加子文档
$skus = [$small, $medium, $large];
$product->addChildDocuments($skus);
// 将产品文档块添加到索引
$updateResponse = $client->addDocument(
$product,
true, // 如果文档存在,则覆盖
10000 // 在 10 秒内提交
);
print_r($updateResponse->getResponse());
上面的例子将输出类似于
SolrObject Object ( [responseHeader] => SolrObject Object ( [status] => 0 [QTime] => 5 ) )