Solr的PHP接口 Solarium

fmms 12年前
     Solarium 是 Solr 的 PHP 开发接口。下面是基本用法:    <br />    <pre class="brush:php; toolbar: true; auto-links: false;"><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>    <img title="Solr的PHP接口 Solarium" border="0" alt="Solr的PHP接口 Solarium" src="https://simg.open-open.com/show/43a794cbac0065848001c31ef9884ea6.gif" width="299" height="49" />    <br />    <br />    <p><a href="/misc/goto?guid=4958186452675297062" target="_blank"><span style="font-weight:bold;">Apache Solr </span></a>是一个开源的搜索服务器。Solr 使用 Java 语言开发,主要基于 HTTP 和 Apache Lucene 实现。Apache Solr 中存储的资源是以 Document 为对象进行存储的。每个文档由一系列的 Field 构成,每个 Field 表示资源的一个属性。Solr 中的每个 Document 需要有能唯一标识其自身的属性,默认情况下这个属性的名字是 id,在 Schema 配置文件中使用:<code><uniqueKey>id</uniqueKey></code>进行描述。</p>    <p>Solr是一个高性能,采用Java5开发,基于Lucene的全文搜索服务器。文档通过Http利用XML加到一个搜索集合中。查询该集合也是通过 http收到一个XML/JSON响应来实现。它的主要特性包括:高效、灵活的缓存功能,垂直搜索功能,高亮显示搜索结果,通过索引复制来提高可用性,提 供一套强大Data Schema来定义字段,类型和设置文本分析,提供基于Web的管理界面等。<br /> <img title="solr.jpg" border="0" alt="solr.jpg" src="https://simg.open-open.com/show/404aba796f3ce70d8f1ed0fea5a75b6c.jpg" width="283" height="156" /></p>