Solr的PHP接口 Solarium

fmms 13年前發布 | 21K 次閱讀 PHP

Solarium 是 Solr 的 PHP 開發接口。下面是基本用法:

<html><head><title>Basic select</title></head><body>

<?php require('../library/Solarium/Autoloader.php'); Solarium_Autoloader::register();

// create a client instance $client = new Solarium_Client();

// get a select query instance $query = $client->createSelect();

// override the default row limit of 10 by setting rows to 30 $query->setRows(30);

// this executes the query with default settings and returns the result $resultset = $client->select($query);

// display the total number of documents found by solr echo 'NumFound: '.$resultset->getNumFound();

// show documents using the resultset iterator foreach ($resultset as $document) {

echo '<hr/><table>';

// the documents are also iterable, to get all fields
foreach($document AS $field => $value)
{
    // this converts multivalue fields to a comma-separated string
    if(is_array($value)) $value = implode(', ', $value);

    echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
}

echo '</table>';

} ?> </body></html></pre> Solr的PHP接口 Solarium

Apache Solr 是一個開源的搜索服務器。Solr 使用 Java 語言開發,主要基于 HTTP 和 Apache Lucene 實現。Apache Solr 中存儲的資源是以 Document 為對象進行存儲的。每個文檔由一系列的 Field 構成,每個 Field 表示資源的一個屬性。Solr 中的每個 Document 需要有能唯一標識其自身的屬性,默認情況下這個屬性的名字是 id,在 Schema 配置文件中使用:<uniqueKey>id</uniqueKey>進行描述。

Solr是一個高性能,采用Java5開發,基于Lucene的全文搜索服務器。文檔通過Http利用XML加到一個搜索集合中。查詢該集合也是通過 http收到一個XML/JSON響應來實現。它的主要特性包括:高效、靈活的緩存功能,垂直搜索功能,高亮顯示搜索結果,通過索引復制來提高可用性,提 供一套強大Data Schema來定義字段,類型和設置文本分析,提供基于Web的管理界面等。
solr.jpg

 本文由用戶 fmms 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!