technosophos / solrapi
A chaining (fluent, builder) API for querying Apache Solr.
Requires
- php: >=5.3.0
- solr-php-client/solrphpclient: >=0.0.20
This package is not auto-updated.
Last update: 2024-09-19 16:30:08 UTC
README
此库提供了一个链式(Fluent)API,用于构建和执行Solr查询。
安装
此库依赖于SolrPHPClient库,它处理Solr客户端-服务器通信。
使用 Packagist/Composer(推荐)
- 获取 Composer 如果您还没有的话。
- 在您的自己的
composer.json
文件中,在 "require" 部分添加technosophos/LibRIS
。
{ "require" { "technosophos/LibRIS": ">=1.0.0" } }
当您在自己的包中运行 php composer.phar install
或 php composer.phar update
时,将添加 SolrAPI 的最新稳定版本(及其依赖项)。
请注意,您可以使用 Composer 来管理您的大部分或所有库依赖项。
旧式方法
- 安装 SolrPHPClient 库。
- 下载此库
- 将此库放置在您的PHP解释器可以访问的位置
- 在您的脚本中包含它(
require 'solrapi.inc'
)
这就完成了。
对于 Drupal 用户
更新:Drupal 版本位于 1.0.0
分支。Drupal 已经偏离了主流PHP,可能与 SolrAPI 的 2.x 版本不兼容。
此库包含一些针对 Drupal apachesolr 模块 的附加功能。
要在 Drupal 下使用此库,您只需安装和配置 apachesolr
模块,然后包含此库。 (我编写了一个简单的模块来执行包含。)
使用此库
由于 SolrAPI 使用函数,而函数不能自动加载,如果您想使用 solarq()
,您需要这样做
<?php require_once 'SolrAPI.php'; ?>
如果您更愿意有 SPR-0 自动加载,并且不关心 solarq()
函数,您可以将 SolrAPI
源代码放入您的包含路径中,打开您的自动加载器,并像这样使用 SolrAPI
<?php $query = new \SolrAPI\Query($string, $options); $query->search(); ?>
查询对象可以像 solrq()
一样进行链式调用。
代码有很好的文档。以下是如何使用此库的一个简单示例
<?php // Execute a search $results = solrq('Search me')->search(); // $result now has a SolrPHPClient search result object. foreach ($results->response->docs as $doc)) { print $doc->title; } ?>
上面的代码执行了一个简单的查询,字符串为 'Search me'。尽管可以构建更复杂的查询。
<?php $results = solrq('monkey wrench') ->useQueryParser(SolrAPI::QUERY_PARSER_DISMAX) // Use the DisMax parser. ->limit(20) // Return 20 items ->offset(1) // Skip the first result (why? I don't know... this is just an example) ->boostQueries('sticky:true^5.0') // Increase ranking on sticky nodes. ->queryFields('title^5.0 body^20.0') // Fields to query, along with their boosts. ->retrieveFields('title, body') // just get the title and body. ->highlight() // Highlight matches in title and body. ->spellcheck() // Check spelling on query string ('blue smurf') and offer alternatives ->sort('title asc') // Sort by title, ascending ->debug(TRUE) // Include debugging info in the output. ->search(); // Execute the search. ?>
Solr 是一个基于高级搜索引擎 Lucene 的先进搜索服务器。为了充分利用此库,您可能需要熟悉 Solr 文档。
此模块是根据 Drupal 编码标准编写的。文档可以使用 Doxygen 提取。
- 更多信息请参阅 wiki
许可
此库根据 GPL 发布,以实现与 Drupal 的兼容性。您也可以选择根据 MIT 许可使用它。
版权 (c) 2010-2012, Matt Butcher
最初由 ConsumerSearch.com 赞助,这是一家纽约时报公司。