简单介绍:最近有人在问我,说mysql5.6既然已经支持了Innodb的全文索引了,为什么依然有人在使用sphinx这样的软件针对mysql 数据库呢.
第一:目前仍然后很多公司在使用mysql5.5,针对innodb 存储引擎则需要全文索引的软件来帮忙
第二:mysql并不是一款中国人开发的服务,因此对中文分词的支持是不行的,由此引出接下来所要讲解的coreseek 中文检索
因有童鞋对安装和基本使用有困惑,因而将本人的基本操作写上,如有疑问请留言
稳定版
wget http://219.232.239.243/uploads/csft/3.2/coreseek-3.2.14.tar.gz curl -O -L http://mirrors.kernel.org/gnu/autoconf/autoconf-2.13.tar.gz
针对低版本则依赖包也要使用低版本的 如果后面遇到must contain _cv_ to be cached类似的报错就是 这个版本太高导致
测试版
wget http://219.232.239.243/uploads/csft/4.0/coreseek-4.1-beta.tar.gz
[root@localhost etc]# yum -y install gcc make gcc-c++ libtool autoconf automake imake mysql-devel libxml2-devel expat-devel [root@localhost mmseg-3.2.14]# history |grep yum 58 yum -y install gcc make libiconv python 75 yum -y install gcc-c++ [root@localhost src]# tar -xf coreseek-4.1-beta.tar.gz [root@localhost src]#curl -O -L http://mirrors.kernel.org/gnu/m4/m4-1.4.13.tar.gz [root@localhost src]# curl -O -L http://mirrors.kernel.org/gnu/autoconf/autoconf-2.65.tar.gz [root@localhost src]# curl -O -L http://mirrors.kernel.org/gnu/automake/automake-1.11.tar.gz [root@localhost src]# curl -O -L http://mirrors.kernel.org/gnu/libtool/libtool-2.2.6b.tar.gz
全部编译安装
./configure --prefix=/usr/local make && make install cd ..
[root@localhost bin]# iconv --version
中文分词需要这个支持
[root@localhost src]# locale LANG=en_US.UTF-8 [root@localhost src]# vim /etc/sysconfig/i18n [root@localhost etc]# cat /etc/sysconfig/i18n #LANG="en_US.UTF-8" LANG="zh_CN.UTF-8" #SYSFONT="latarcyrheb-sun16" SYSFONT="latarcyrheb-sun16" [root@localhost ~]# su - root(或者重启环境才会生效) [root@localhost src]# tar -xf coreseek-4.1-beta.tar.gz [root@localhost var]# cd /usr/local/src/coreseek-4.1-beta/testpack/var [root@localhost var]# cat test/test.xml <?xml version="1.0" encoding="utf-8"?> <sphinx:docset> <sphinx:schema> <sphinx:field name="subject"/> <sphinx:field name="content"/> <sphinx:attr name="published" type="timestamp"/> <sphinx:attr name="author_id" type="int" bits="16" default="1"/> </sphinx:schema> <sphinx:document id="1"> <subject>愚人节最佳蛊惑爆料 谷歌300亿美元收购百度</subject> <published>1270131607</published> <content>据国外媒体报道,谷歌将巨资收购百度,涉及金额高达300亿美元。谷歌借此重返大陆市场。 该报道称,目前谷歌与百度已经达成了收购协议,将择机对外公布。百度的管理层将100%保留,但会将项目缩减,包括有啊商城,以及目前实施不力的凤巢计划。正在进行测试阶段的视频网站qiyi.com将输入更多的Youtube资源。(YouTube在大陆区因内容审查暂不能访问)。
看到了有中文支持
[root@localhost src]# cd coreseek-4.1-beta/mmseg-3.2.14/ [root@localhost mmseg-3.2.14]# ./bootstrap [root@localhost mmseg-3.2.14]# ./configure --prefix=/usr/local/mmseg/ [root@localhost mmseg-3.2.14]# make && make install [root@localhost bin]# /usr/local/mmseg/bin/mmseg -d /usr/local/mmseg/etc/ [root@localhost coreseek-3.2.14]# cd csft-3.2.14/ [root@localhost csft-3.2.14]# ls acinclude.m4 configure.ac INSTALL pymmseg sphinx-min.conf.in aclocal.m4 contrib libexpat python.m4 sphinx.spec api COPYING libstemmer_c smoke.sh sphinx.workspace buildconf.sh csft.doc Makefile.am sphinx03.sln src codeblocks csft.pytest Makefile.in sphinx05.sln test config doc misc sphinx08.sln win configure example.sql mysqlse sphinx.conf.in [root@localhost csft-3.2.14]# sh buildconf.sh [root@localhost csft-4.1]# ./configure --prefix=/usr/local/coreseek/ --without-python --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/mmseg/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg/lib/ --with-mysql [root@localhost csft-4.1]# make && make install 至此xml 的已经编译完成
支持mysql 的方式
[root@localhost csft-4.1]# yum -y install mysql-devel libxml2-devel expat-devel Make clean (清楚之前的编译) ./configure --prefix=/usr/local/coreseek --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/mmseg/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg/lib/ --with-mysql Make && make install 至此Mysql数据源安装完成
使用默认的sql 和配置文件做一次
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘test‘@‘%‘ WITH GRANT OPTION; mysql> GRANT PROXY ON ‘‘@‘‘ TO ‘test‘@‘%‘ WITH GRANT OPTION; mysql>flush privileges; [root@localhost etc]# mysql -utest < example.sql [root@localhost etc]# pwd /usr/local/coreseek/etc [root@localhost etc]# cp sphinx.conf.dist csft.conf
[root@localhost etc]# vi csft.conf
打开第32行
csft.conf
sql_sock = /tmp/mysql.sock 根据你的mysql 的这个的实际位置
sql_query_pre = SET NAMES utf8
找到sql_query_info = SELECT * FROM documents WHERE id=$id 在该行上面加上 sql_query_info_pre = SET NAMES utf8 (作用是为了中文能显示)
[root@localhost etc]# /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft.conf --all Coreseek Fulltext 4.1 [ Sphinx 2.0.2-dev (r2922)] Copyright (c) 2007-2011, Beijing Choice Software Technologies Inc (http://www.coreseek.com) using config file ‘/usr/local/coreseek/etc/csft.conf‘... indexing index ‘test1‘... collected 4 docs, 0.0 MB sorted 0.0 Mhits, 100.0% done total 4 docs, 193 bytes total 0.007 sec, 24823 bytes/sec, 514.46 docs/sec indexing index ‘test1stemmed‘... collected 4 docs, 0.0 MB sorted 0.0 Mhits, 100.0% done total 4 docs, 193 bytes total 0.003 sec, 49411 bytes/sec, 1024.06 docs/sec skipping non-plain index ‘dist1‘... skipping non-plain index ‘rt‘... total 6 reads, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg total 18 writes, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg [root@localhost data]# pwd /usr/local/coreseek/var/data [root@localhost data]# ls 这些文件就是上面indexer命令生成的 test1.spa test1.sph test1.spk test1.spp test1stemmed.spa test1stemmed.sph test1stemmed.spk test1stemmed.spp test1.spd test1.spi test1.spm test1.sps test1stemmed.spd test1stemmed.spi test1stemmed.spm test1stemmed.sps
[root@localhost data]# /usr/local/coreseek/bin/search test #就可以搜索到定义的数据库里的表内容了 1. document=1, weight=2421, group_id=1, date_added=Wed Aug 13 01:29:11 2014 id=1 group_id=1 group_id2=5 date_added=2014-08-13 01:29:11 title=test one content=this is my test document number one. also checking search within phrases. 2. document=2, weight=2421, group_id=1, date_added=Wed Aug 13 01:29:11 2014 id=2 group_id=1 group_id2=6 date_added=2014-08-13 01:29:11 title=test two content=this is my test document number two 3. document=4, weight=1442, group_id=2, date_added=Wed Aug 13 01:29:11 2014 id=4 group_id=2 group_id2=8 date_added=2014-08-13 01:29:11 title=doc number four content=this is to test groups mysql> update test.documents set content=‘草泥马‘; [root@localhost etc]# /usr/local/coreseek/bin/search test Coreseek Fulltext 4.1 [ Sphinx 2.0.2-dev (r2922)] Copyright (c) 2007-2011, Beijing Choice Software Technologies Inc (http://www.coreseek.com) using config file ‘/usr/local/coreseek/etc/csft.conf‘... index ‘test1‘: query ‘test ‘: returned 3 matches of 3 total in 0.000 sec displaying matches: 1. document=1, weight=2421, group_id=1, date_added=Wed Aug 13 01:29:11 2014 id=1 group_id=1 group_id2=5 date_added=2014-08-13 01:29:11 title=test one content=草泥马 2. document=2, weight=2421, group_id=1, date_added=Wed Aug 13 01:29:11 2014 id=2 group_id=1 group_id2=6 date_added=2014-08-13 01:29:11 title=test two content=草泥马 3. document=4, weight=1442, group_id=2, date_added=Wed Aug 13 01:29:11 2014 id=4 group_id=2 group_id2=8 date_added=2014-08-13 01:29:11 title=doc number four content=草泥马
详细具体使用的方法参照:http://www.coreseek.cn/
本文出自 “笑嘻嘻啊” 博客,请务必保留此出处http://zuoyuezong.blog.51cto.com/6444039/1539889
原文地址:http://zuoyuezong.blog.51cto.com/6444039/1539889