PHP扩展之针对搜索引擎的扩展(二)—— Sphinx简介、安装及使用
2014-11-07 00:00
1851 查看
一、简介及安装
该扩展提供了针对Sphinx搜索客户端开发库的绑定. Sphinx是一个独立的搜索引擎系统,其目的是为其他相关程序和应用提供快速的、规模可扩展的全文搜索功能. Sphinx有着良好的设计,可以很方便的与SQL数据库结合,并使用脚本语言调用. Sphinx 以及 其客户端库 可以从 官方站点获取,中文用户也可以从Coreseek获取支持中文的版本和服务。
安装需求:需要PHP5.2.2及以上PHP版本。
安装步骤请参考:Linux下编译安装Sphinx、中文分词coreseek及PHP的sphinx扩展
安装过程中,如果 ./configure 不能正确找到 libsphinxclient 文件 (例如, 他被安装在用户自己定义的目录中),使用 ./configure --with-sphinx=$PREFIX来制定libsphinxclient的具体位置($PREFIX是libsphinxclient的安装位置)。
编译安装:
从http://pecl.php.net/package/sphinx下载所需的sphinx扩展源码安装包,解压到指定目录,进入该目录。
二、使用实例
Example #1 基本使用范例
以上例程的输出类似于:
三、SphinxClient 类
SphinxClient 为 Sphinx 提供了面向对象的接口
SphinxClient::addQuery — Add query to multi-query batch
SphinxClient::buildExcerpts — Build text snippets
SphinxClient::buildKeywords — Extract keywords from query
SphinxClient::close — 关闭先前打开的持久连接
SphinxClient::__construct — Create a new SphinxClient object
SphinxClient::escapeString — Escape special characters
SphinxClient::getLastError — Get the last error message
SphinxClient::getLastWarning — Get the last warning
SphinxClient::open — 建立到搜索服务端的持久连接
SphinxClient::query — 执行搜索查询
SphinxClient::resetFilters — Clear all filters
SphinxClient::resetGroupBy — Clear all group-by settings
SphinxClient::runQueries — Run a batch of search queries
SphinxClient::setArrayResult — 控制搜索结果集的返回格式
SphinxClient::setConnectTimeout — Set connection timeout
SphinxClient::setFieldWeights — Set field weights
SphinxClient::setFilter — 增加整数值过滤器
SphinxClient::setFilterFloatRange — Add new float range filter
SphinxClient::setFilterRange — Add new integer range filter
SphinxClient::setGeoAnchor — Set anchor point for a geosphere distance calculations
SphinxClient::setGroupBy — Set grouping attribute
SphinxClient::setGroupDistinct — Set attribute name for per-group distinct values count calculations
SphinxClient::setIDRange — Set a range of accepted document IDs
SphinxClient::setIndexWeights — Set per-index weights
SphinxClient::setLimits — 设置返回结果集偏移量和数目
SphinxClient::setMatchMode — 设置全文查询的匹配模式
SphinxClient::setMaxQueryTime — Set maximum query time
SphinxClient::setOverride — Sets temporary per-document attribute value overrides
SphinxClient::setRankingMode — Set ranking mode
SphinxClient::setRetries — Set retry count and delay
SphinxClient::setSelect — Set select clause
SphinxClient::setServer — 设置searchd的主机名和TCP端口
SphinxClient::setSortMode — Set matches sorting mode
SphinxClient::status — Queries searchd status
SphinxClient::updateAttributes — Update document attributes
该扩展提供了针对Sphinx搜索客户端开发库的绑定. Sphinx是一个独立的搜索引擎系统,其目的是为其他相关程序和应用提供快速的、规模可扩展的全文搜索功能. Sphinx有着良好的设计,可以很方便的与SQL数据库结合,并使用脚本语言调用. Sphinx 以及 其客户端库 可以从 官方站点获取,中文用户也可以从Coreseek获取支持中文的版本和服务。
安装需求:需要PHP5.2.2及以上PHP版本。
安装步骤请参考:Linux下编译安装Sphinx、中文分词coreseek及PHP的sphinx扩展
安装过程中,如果 ./configure 不能正确找到 libsphinxclient 文件 (例如, 他被安装在用户自己定义的目录中),使用 ./configure --with-sphinx=$PREFIX来制定libsphinxclient的具体位置($PREFIX是libsphinxclient的安装位置)。
编译安装:
从http://pecl.php.net/package/sphinx下载所需的sphinx扩展源码安装包,解压到指定目录,进入该目录。
./configure --with-php-config=/usr/local/php/bin/php-config --with-sphinx=/usr/local/libsphinxclient make sudo make install
二、使用实例
Example #1 基本使用范例
<?php $s = new SphinxClient; $s->setServer("localhost", 6712); $s->setMatchMode(SPH_MATCH_ANY); $s->setMaxQueryTime(3); $result = $s->query("test"); var_dump($result); ?>
以上例程的输出类似于:
array(10) { ["error"]=> string(0) "" ["warning"]=> string(0) "" ["status"]=> int(0) ["fields"]=> array(3) { [0]=> string(7) "subject" [1]=> string(4) "body" [2]=> string(6) "author" } ["attrs"]=> array(0) {} ["matches"]=> array(1) { [3]=> array(2) { ["weight"]=> int(1) ["attrs"]=> array(0) {} } } ["total"]=> int(1) ["total_found"]=> int(1) ["time"]=> float(0) ["words"]=> array(1) { ["to"]=> array(2) { ["docs"]=>int(1) ["hits"]=>int(1) } } }
三、SphinxClient 类
SphinxClient 为 Sphinx 提供了面向对象的接口
SphinxClient::addQuery — Add query to multi-query batch
SphinxClient::buildExcerpts — Build text snippets
SphinxClient::buildKeywords — Extract keywords from query
SphinxClient::close — 关闭先前打开的持久连接
SphinxClient::__construct — Create a new SphinxClient object
SphinxClient::escapeString — Escape special characters
SphinxClient::getLastError — Get the last error message
SphinxClient::getLastWarning — Get the last warning
SphinxClient::open — 建立到搜索服务端的持久连接
SphinxClient::query — 执行搜索查询
SphinxClient::resetFilters — Clear all filters
SphinxClient::resetGroupBy — Clear all group-by settings
SphinxClient::runQueries — Run a batch of search queries
SphinxClient::setArrayResult — 控制搜索结果集的返回格式
SphinxClient::setConnectTimeout — Set connection timeout
SphinxClient::setFieldWeights — Set field weights
SphinxClient::setFilter — 增加整数值过滤器
SphinxClient::setFilterFloatRange — Add new float range filter
SphinxClient::setFilterRange — Add new integer range filter
SphinxClient::setGeoAnchor — Set anchor point for a geosphere distance calculations
SphinxClient::setGroupBy — Set grouping attribute
SphinxClient::setGroupDistinct — Set attribute name for per-group distinct values count calculations
SphinxClient::setIDRange — Set a range of accepted document IDs
SphinxClient::setIndexWeights — Set per-index weights
SphinxClient::setLimits — 设置返回结果集偏移量和数目
SphinxClient::setMatchMode — 设置全文查询的匹配模式
SphinxClient::setMaxQueryTime — Set maximum query time
SphinxClient::setOverride — Sets temporary per-document attribute value overrides
SphinxClient::setRankingMode — Set ranking mode
SphinxClient::setRetries — Set retry count and delay
SphinxClient::setSelect — Set select clause
SphinxClient::setServer — 设置searchd的主机名和TCP端口
SphinxClient::setSortMode — Set matches sorting mode
SphinxClient::status — Queries searchd status
SphinxClient::updateAttributes — Update document attributes
相关文章推荐
- 【整理】Linux下中文检索引擎coreseek4安装,以及PHP使用sphinx的三种方式(sphinxapi,sphinx的php扩展,SphinxSe作为mysql存储引擎)
- 【整理】Linux下中文检索引擎coreseek4安装,以及PHP使用sphinx的三种方式(sphinxapi,sphinx的php扩展,SphinxSe作为mysql存储引擎)
- 提高define性能的php扩展hidef的安装和使用
- 提高define性能的php扩展hidef的安装和使用
- centos 使用phpize动态安装php扩展
- MongoDB定义&安装&使用&php扩展
- php学习笔记(二十四)php使用memcache扩展库的使用和安装
- ubuntu下安装和使用php的fileinfo扩展
- PHP安装与使用VLD查看opcode代码【PHP安装第三方扩展的方法】
- Linux上的SCWS安装与使用(包括PHP扩展)
- MongoDB的安装使用以及安装php扩展
- windows+sphinx+php 安装+配置+使用
- 使用PHP+Sphinx建立高效的站内搜索引擎
- PHP图像处理(二) GraphicsMagick 安装扩展及使用方法
- 使用PHP+Sphinx建立高效的站内搜索引擎
- Python开发之扩展库的安装指南及Suds(Webservice)的使用简介
- php安装使用http扩展类
- PHP扩展开发-08-数组的使用以及HashTable简介
- php安装使用http扩展类