2024 日本 PHP 研討會

SolrClient::getById

(PECL solr >= 2.2.0)

SolrClient::getById透過 ID 取得文件。使用 Solr Realtime Get (RTG)

說明

public SolrClient::getById(字串 $id): SolrQueryResponse

透過 ID 取得文件。使用 Solr Realtime Get (RTG)。

參數

id

文件 ID

回傳值

SolrQueryResponse

範例

範例 #1 SolrClient::getById() 範例

<?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_PATH
);

$client = new SolrClient($options);
$response = $client->getById('GB18030TEST');
print_r($response->getResponse());

?>

以上範例會輸出類似以下的內容

SolrObject Object
(
    [doc] => SolrObject Object
        (
            [id] => GB18030TEST
            [name] => Array
                (
                    [0] => Test with some GB18030 encoded characters
                )

            [features] => Array
                (
                    [0] => No accents here
                    [1] => 这是一个功能
                    [2] => This is a feature (translated)
                    [3] => 这份文件是很有光泽
                    [4] => This document is very shiny (translated)
                )

            [price] => Array
                (
                    [0] => 0
                )

            [inStock] => Array
                (
                    [0] => 1
                )

            [_version_] => 1510294336239042560
        )

)

另請參閱

新增註解

使用者貢獻的註解

此頁面沒有使用者貢獻的註解。
To Top