sphinx全称SQL Phrase Index(查询词组索引),是一个基于SQL的全文检索引擎
coreseek是基于sphinx的带中文分词功能的全文检索引擎
流程:php搜索 -> sphinx根据搜索关键字从索引中找出相关的MYSQL主键 -> 根据主键到MYSQL中找出相关数据。
sphinx缺点:
数据库必须要有主键;主键必须为整型;不负责数据存储;配置不灵活。
中文分词需要注意编码:php mysql sphinx 全部 utf8 Mysql > \s 查看 msyql状态
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
//下载coreseek wget http://www.coreseek.cn/uploads/csft/4.0/coreseek-4.1-beta.tar.gz //解压缩 tar zxvf coreseek-4.1-beta.tar.gz //先安装中文分词 mmseg cd coreseek-4.1-beta/mmseg-3.2.14 //配置mmseg ./configure --prefix=/usr/local/mmseg //配置时如果以下错误 config.status: error: cannot find input file: src/Makefile.in //解决办法: aclocal libtoolize --force //运行后有一个错误,不用管它。 automake --add-missing autoconf autoheader make clean //重新配置 ./configure --prefix=/usr/local/mmseg //编译 make //安装 make install //安装完成后,mmseg使用的词典和配置文件,自动安装在/usr/local/mmseg/etc中 //再安装coreseek cd /coreseek-4.1-beta/csft-4.1 //执行sh,忽略warning错误 sh buildconf.sh //配置coreseek ./configure --prefix=/usr/local/coreseek --with-mysql=/usr/local/mysql --with-mmseg=/usr/local/mmseg --with-mmseg-includes=/usr/local/mmseg/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg/lib/ //编译 make //安装 make install |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
配置coreseek cd /usr/local/coreseek/etc/ cp sphinx.conf.dist csft.conf vim csft.conf //配置如下 //主数据源 source main{ //配置数据库连接信息,这里略过... sql_query = select * from test //配置主数据源sql //其他暂时注释掉 } //增量数据源 source delta:main{} 全部注释掉 //主索引 index main{ source = main //source指向主数据源 path = /usr/local/coreseek/var/data/test //主索引路径 需要在相应路径touch一个 charset_dictpath = /usr/local/mmseg3/etc/ //指定中文utf-8必须指定这个路径 charset_type = zh_cn.utf-8 //设置编码 //其他全部取默认值 } //增量索引 index delta:main{} 分布式索引 index dist1{} RT实时索引定义 index rt{} 全部注释掉 //索引器 indexer{ mem_limit = 256M //内存大小,根据实际情况,通常3分之1到2分之1 } //服务进程 searchd{ listen = 9312 //监听9312端口,另外个暂时注释掉 compat_sphinxql_magics = 0 } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
//创建mysql数据表 create table test( id int unsigned not null primary key auto_increment, title varchar(128) not null default '', content varchar(255) not null default '') engine=innodb default charset=utf8; //插入测试数据 insert into test (title,content) values('hello world', '你好!世界!'); cd /usr/local/coreseek/bin //indexer 创建索引命令 -c指定索引文件 --all对所有索引重新编制索引 --rotate用于轮换索引,主要是在不停止服务的时候,增加索引 --merge合并索引 ./indexer --all //在searchd状态下需要用--rotate //searchd 启动进程命令 -h查看帮助 -c指定配置文件 --stop停止服务 -p指定端口 ./searchd //search 命令行搜索命令 ./search 世界 //测试成功,显示如下内容 displaying matches: 1. document=1, weight=1500 words: 1. '世界': 1 documents, 1 hits |
参考手册:http://www.coreseek.cn/docs/coreseek_4.1-sphinx_2.0.1-beta.html
排错地址:http://www.coreseek.cn/products-install/faq/