函数名称:SolrClient::getById()
适用版本:Solr PECL扩展 >= 2.0.0
函数说明:SolrClient::getById()函数用于通过唯一标识符(ID)从Solr服务器获取文档。
用法:
SolrClient::getById ( string $id [, array $queryOptions ] ) : SolrQueryResponse
参数:
返回值:
示例:
// 创建Solr客户端
$client = new SolrClient(array(
'hostname' => 'localhost',
'port' => 8983,
'path' => '/solr/',
));
// 从Solr服务器获取文档
$id = '12345'; // 假设文档的唯一标识符为12345
$queryOptions = array(
'fl' => 'id,name,description', // 指定要返回的字段
'wt' => 'json' // 指定响应格式为JSON
);
$response = $client->getById($id, $queryOptions);
// 处理响应
if ($response->success()) {
$document = $response->getResponse();
echo "文档ID: " . $document['response']['docs'][0]['id'] . "\n";
echo "文档名称: " . $document['response']['docs'][0]['name'] . "\n";
echo "文档描述: " . $document['response']['docs'][0]['description'] . "\n";
} else {
echo "获取文档失败: " . $response->getHttpStatusMessage() . "\n";
}
注意事项: