首先先说一下coreseek,其实就是支持中文索引的sphinx + 一个中文分词系统。网上很多教程都教你怎么安装sphinx。其实sphinx对于中文站点卵用都没有,因为sphinx是不支持中文搜索的。
另外说一下sphinx仅仅是一个索引系统,本身并不保存数据,仅仅保留数据索引(sphinx并不能当mysql使用,当你需要查询完整数据时,仅能通过索引的ID查询mysql,获取完整内容)。sphinx的使用更偏向于模糊查询,举个例子,比如你用mysql模糊查询 like "%手表%"时,你的商品标题“男士时尚表”时,mysql是无法检索出来的。但是使用coreseek就可以检索出这个商品(这个在用户体验中显得十分重要)。
好了,说回正题,xampp的安装略过。这个安装过程网上太多了。直接上coreseek的安装教程
1. 下载coreseek,近期发现下载不稳定,建议先用迅雷下载回来,再上传到服务器。Coreseek的官方网址为:http://www.coreseek.cn。我这里下载的是4.1版本。另外我还习惯把下载文件放在 /opt/down 目录里面(如果没有/opt 里面没有down,需要先创建一个目录 mkdir /opt/down)。
cd /opt/down
wget http://www.coreseek.cn/uploads/csft/4.0/coreseek-4.1-beta.tar.gz
2. 解压下载的文件
tar -zvxf coreseek-4.1-beta.tar.gz
3. 进入解压文件的目录。
cd coreseek-4.1-beta
4. 目录详情
csft 实际就是支持中文索引的sphinx。
mmseg 是一个中文分词系统。
[root@iZwz9h2pyw48k12kk2q1nvZ coreseek-4.1-beta]# ls
csft-4.1 mmseg-3.2.14 README.txt testpack
5. 安装之前必须确认你的系统已经安装下面的程序。
yum -y install make gcc gcc++ gcc-c++ libtool autoconfautomake imake
6. 因为我Linux上面用的是xampp,所以就不装数据库支持了。如果你不是xampp的话尝试安装下面的mysql扩展
yum -y install mysql-devel libxml2-devel expat-devel
7. 接下来我们先安装mmseg中文分词系统。进入mmseg目录
cd mmseg-3.2.14
./bootstrap
./configure --prefix=/usr/mmseg
make && make install
12. 进入mmseg目录。里面有4个文件夹。我只知道2个目录的作用。
bin 运行程序目录(bin里面只有一个叫mmseg的程序)
etc 词库目录(里面是词库的文件。如下图2。uni.lib 是用 unigram.txt编译出来的二进制文件,如何编译忘记了。这个抱歉,时间关系,这个不说了。总之直接用也是可以的)
cd /usr/mmseg
13. 测试mmseg。在mmseg目录下建立一个txt文本(不会用vi编辑就直接用sftp连接服务器,然后上传一个文本)。我已经提前建好了一个txt文本。内容是“我是中国人”。
建好文本后,我们用命令行测试一下,这时mmseg已经把刚才文本里面的文字分成“我们,是,中国人”。
bin/mmseg -d etc 1.txt
14. 安装好mmseg后,我们开始安装coreseek。先进入coreseek安装目录(注意上面说了,我是把解压文件放在/opt/down里面的,新手要注意别乱来)。
cd /opt/down/coreseek-4.1-beta/csft-4.1
sh buildconf.sh
这里我遇到了一个错误,大致如下图(真不知道网上教程直接就能成功的人是怎么想的,这里不再吐槽了)。
错误提示:(我贴这个代码的原因是为了以后别人搜索这个问题的时候好看到这个帖子,我是找了很多资料才找到原因的。真是用心良苦啊~~~~~~~)
automake: warnings are treated as errors
/usr/share/automake-1.13/am/library.am: warning: 'libstemmer.a': linking libraries using a non-POSIX
/usr/share/automake-1.13/am/library.am: archiver requires 'AM_PROG_AR' in 'configure.ac'
libstemmer_c/Makefile.am:2: while processing library 'libstemmer.a'
/usr/share/automake-1.13/am/library.am: warning: 'libsphinx.a': linking libraries using a non-POSIX
/usr/share/automake-1.13/am/library.am: archiver requires 'AM_PROG_AR' in 'configure.ac'
src/Makefile.am:14: while processing library 'libsphinx.a'
在编译VLC时遇到提示:
/usr/share/automake-1.14/am/ltlibrary.am: warning: 'lib/libtiger.la': linking libtool libraries using a non-POSIX
/usr/share/automake-1.14/am/ltlibrary.am: archiver requires 'AM_PROG_AR' in 'configure.ac'
查了N久网页,最终的解决办法让人想骂娘。
在编译的库目录下,找到'configure.ac',用文本编辑器打开,
AC_PROG_CC_C_O
AC_PROG_LIBTOOL
AC_PROG_GREP
AC_PROG_NM
AC_PROG_SED
找到类似以上的文本,在最后一行添加AM_PROG_AR即可。
上传文件到服务器后,我继续执行检测环境
sh buildconf.sh
错误提示
configure.ac:231: the top level
configure.ac:62: error: required file 'config/ar-lib' not found
configure.ac:62: 'automake --add-missing' can install 'ar-lib'
解决这个问题后,再检查环境,发现我的环境没问题了,下面开始安装。
16. 编译coreseek。
./configure --prefix=/usr/coreseek --with-mysql=/opt/lampp --with-mmseg=/usr/mmseg --with-mmseg-includes=/usr/mmseg/include/mmseg/ --with-mmseg-libs=/usr/mmseg/lib/
说明一下:
--prefix=/usr/coreseek //需要coreseek安装到该目录。
--with-mysql=/opt/lampp //数据库的地址,我用的是xampp,所以地址是这个。
--with-mmseg=/usr/mmseg //mmseg 目录
--with-mmseg-includes=/usr/mmseg/include/mmseg/
--with-mmseg-libs=/usr/mmseg/lib/ //这个是mmseg库文件的目录
编译成功后,最后会返回“Thank you for choosing Sphinx!”
17. 编译成功后,继续进行安装。
make && make install
我在这里又出错了,具体如下:
错误代码:
Making all in src
make[1]: Entering directory `/opt/down/coreseek-4.1-beta/csft-4.1/src'
/bin/sh svnxrev.sh ..
make all-am
make[2]: Entering directory `/opt/down/coreseek-4.1-beta/csft-4.1/src'
g++ -DHAVE_CONFIG_H -I. -I../config -DSYSCONFDIR="\"/usr/coreseek/etc\"" -DDATADIR="\"/usr/coreseek/var/data\"" -I/usr/local/include -pthread -I/opt/lampp/include/mysql -I/opt/lampp/include/mysql/.. -I/usr/mmseg/include/mmseg/ -Wall -g -D_FILE_OFFSET_BITS=64 -O3 -DNDEBUG -MT sphinx.o -MD -MP -MF .deps/sphinx.Tpo -c -o sphinx.o sphinx.cpp
In file included from sphinx.cpp:16:0:
sphinx.h:72:19: fatal error: mysql.h: No such file or directory
#include
^
compilation terminated.
make[2]: *** [sphinx.o] Error 1
make[2]: Leaving directory `/opt/down/coreseek-4.1-beta/csft-4.1/src'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/opt/down/coreseek-4.1-beta/csft-4.1/src'
make: *** [all-recursive] Error 1
解决办法:
修改 src/sphinx.h文件。
我解决这个问题后再执行 “mark && mark install” 就正常安装了。ls /usr目录后可以看到coreseek文件夹。
18. coreseek文件目录说明
bin //coreseek程序目录
indexer //用户建立sphinx索引
indextool //暂时不知道怎么使用
searchd //用户启动或者关闭sphinx端口服务
search //我暂时知道用来测试搜索的。
spelldump // 这个不知道干嘛用的
etc //存放sphinx配置的目录
19. 到此安装已经完成,关于coreseek的配置与测试,我将会在下一遍文章中介绍。