sphinx基础

安装sphinx
1)下载对应版本的源:wget http://sphinxsearch.com/downloads/release/
2)解压:tar zxvf sphinx-xx
3)进入目录内:cd sphinx-xx
4)配置:./configure --prefix=需要安装到哪里 --with-mysql=mysql的安装路径
5)编译安装:make && make install

sphinx命令
indexer 创建索引
search 命令行搜索
search 索引名
searchd 启动进程

配置sphinx(安装目录etc)
1)复制配置文件:cp sphinx.conf.dist sphinx.conf
2)修改配置文件(重要):
主数据源:
source main{
type=mysql #数据库类型
sql_host=localhost #MySQL主机IP
sql_user=root #MySQL用户名
sql_pass= #MySQL密码
sql_db= #MySQL数据库
sql_port=3306 #MySQL端口
sql_sock= #指定sock文件
sql_query_pre=SET NAMES UTF8 #MySQL检索编码
sql_query_pre=SET SESSION query_cache_type=OFF #关闭缓存
sql_query=select * #获取数据的SQL语句
sql_query_info = #
}
增量数据源:
source delta:main{}
主数据索引:
index main{
source=main #索引的数据源来源
path=安装路径/sphinx/var/data/main #索引存放路径
charset_type=utf-8 #编码
charset_table=* #打开该注释,编码结构
}
增量数据索引:
index delta:main{}
分布式索引:
index dist1{}
索引器(2g内存建议分配256m):
indexer{
mem_limit=分配空间M
}
服务进程:
searchd{
listen= #端口 默认不用修改
}

创建索引(indexer):
-c 指定配置文件
--all 对所有索引重新编制索引
--rotate 用于轮换索引,在不停止服务的时候增加索引
--merge 合并索引,把增量索引合并到主索引

coreseek安装:
1)下载对应版本的源:wget http://www.coreseek.cn/uploads/csft/4.0/coreseek-4.1-beta.tar.gz
2)解压:tar zxvf coreseek-xx
3)进入目录内:cd coreseek-xx/mmseg-xx 先安装中文分词
4)配置:./configure --prefix=需要安装到哪里
如果出错执行:automake,然后继续第4步
5)编译安装:make && make install
6)之后安装coreseek,先进入coreseek目录:cd ../csft-xx/
7)配置:./configure --prefix=需要安装到哪里 --width-mysql=MySQL安装的目录 --width-mmseg=MmSEG安装的目录 --with-mmseg-includes=MmSEG安装的库目录在include/mmseg/级别 --with-mmseg-libs=MmSEG安装的库目录
8)编译安装:make && make install

coreseek配置:
1)复制配置文件:cp sphinx.conf.dist csft.conf
2)修改配置文件(重要)之前sphinx中的均需修改,还有一些独自修改的特性:
index main{
#注释一下语句
#stopwords=路径
#wordforms=路径
#exceptions=路径
#charset_type=sbcs
#添加下面语句,可把中文分词加入到配置文件中
charset_type=zh_cn.uft-8
charset_dictpath=mmseg安装目录的etc下
}

PHP使用Sphinx必要条件:
1)启动coreseek并在后台执行:在coreseek的bin目录下执行:./searchd 默认端口9312。
2)加载sphinx模块:wget http://pecl.php.net/get/sphinx-1.1.0.tgz
3)解压:tar zxvf sphinx-xx
4)进入目录内:cd sphinx-xx
5)生成configure:/usr/local/webserver/php/bin/phpize
5-1)安装libsphinxclient:在最初解压的程序包中进入csft-xx/api/libsphinxclient/目录
5-2)./configure
5-3)make && make install
6)返回之前目录然后配置:./configure --width-php-config=安装路径下的/bin/php-config --with-sphinx
7)make && make install

PHP开发Sphinx:
$sphinx=new SphinxClient();
$sphinx->SetServer("localhost",9312);
$sphinx->SetMatchMode(SPH_MATCH_ANY);//分词
//$sphinx->SetLimits(0,0);
$result=$sphinx->query("词","哪个索引可用*");
$sphinx->buildExcerpts("文档数组","索引","关键词",$opts)//高亮

posted @ 2015-08-23 16:34  ddliang  阅读(180)  评论(0编辑  收藏  举报