您的位置:首页 > 数据库 > MySQL

Sphinx + MySQL + 中文分词安装配置

2013-06-10 20:01 615 查看
1.所需要下载的软件

mmseg-0.7.3.tar.gz --- 中文分词
http://www.coreseek.com/uploads/sources/mmseg-0.7.3.tar.gz
mysql-5.1.49.tar.gz --- mysql-5.1.14源代码

wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.49.tar.gz/from/http://mysql.ntu.edu.tw/
sphinx-0.9.8-rc2.tar.gz --- sphinx-0.9.8-rc2源代码
http://www.sphinxsearch.com/downloads/sphinx-0.9.8-rc2.tar.gz
fix-crash-in-excerpts.patch --- sphinx支持分词补丁
http://www.coreseek.com/uploads/sources/fix-crash-in-excerpts.patch
sphinx-0.98rc2.zhcn-support.patch --- sphinx支持分词补丁
http://www.coreseek.com/uploads/sources/sphinx-0.98rc2.zhcn-support.patch
2.安装libmmseg

debian-test-server:/home/software# tar zxvf mmseg-0.7.3.tar.gz

./configure

make && make install

编译的时候报如下的错误:

css/UnigramCorpusReader.cpp:89: error: 'strncmp' was not declared in this scope

解决办法:

vi src/css/UnigramCorpusReader.cpp 

添加:#include <string.h>

重新编译以后就没有错误了。

简单测试下mmseg

debian-test-server:/home/software/mmseg-0.7.3# mmseg

Coreseek COS(tm) MM Segment 1.0

Copyright By Coreseek.com All Right Reserved.

Usage: mmseg <option> <file>

-u <unidict>           Unigram Dictionary

-r           Combine with -u, used a plain text build Unigram Dictionary, default Off

-b <Synonyms>           Synonyms Dictionary

-h            print this help and exit

3.安装MySQL及Sphinx for MySQL存储引擎

解压缩sphinx,将sphinx主目录下mysqlse目录下的文件拷贝到MySQL的storage/sphinx目录下,当然sphinx目录是新创建的目录。

两个目录下的文件分别如下,是相同的。

debian-test-server:/home/software/sphinx-0.9.8-rc2/mysqlse# ls

CMakeLists.txt  Makefile.am   ha_sphinx.cc  plug.in             sphinx.5.0.27.diff

HOWTO.txt       gen_data.php  ha_sphinx.h   sphinx.5.0.22.diff  sphinx.5.0.37.diff

debian-test-server:/home/software/mysql-5.1.49/storage/sphinx# ls

CMakeLists.txt  Makefile     Makefile.in   ha_sphinx.cc  plug.in            sphinx.5.0.27.diff

HOWTO.txt       Makefile.am  gen_data.php  ha_sphinx.h   sphinx.5.0.22.diff sphinx.5.0.37.diff

debian-test-server:/home/software/mysql-5.1.49# sh BUILD/autorun.sh

BUILD/autorun.sh: line 23: aclocal: command not found

Can't execute aclocal

google了一下,发现是需要安装automake模块
http://ronaldbradford.com/blog/compiling-mysql-5051-under-ubuntu-710-2008-01-14/
aptitude install automake

后来还报如下的错误

BUILD/autorun.sh: line 26: libtoolize: command not found

Can't execute libtoolize

aptitude install libtool

安装过程中遇到了很多次不是缺少这个包、就是缺少那个包的错误,还好一一都解决了,遇到困难有时并不一定是坏事,可以考验自己处理各种困难的能力,下次再次遇到时就相对简单一些了。

执行configure之前,首先要执行autorun.sh脚本,否则sphinx引擎无法正确安装,这一步非常重要,请千万注意。

sh BUILD/autorun.sh

如果你遇到下面的错误

编译的时候还报了下面的错误,最后在configure后面加上选项--sysconfdir=/etc后,编译的时候就不报错了。

my_new.cc

../include/my_global.h:1103: error: redeclaration of C++ built-in type bool

make[1]: *** [my_new.o] Error 1

make[1]: Leaving directory `/home/mysql-5.1.49/mysys'

make: *** [all-recursive] Error 1

./configure --with-plugins=sphinx --prefix=/usr/local/webserver/mysql/ --sysconfdir=/etc --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client
--with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile

debian-test-server:/home/software/mysql-5.1.49# ./configure --help | grep sphinx

                          innodb_plugin myisam myisammrg ndbcluster sphinx.

  Plugin Name:      sphinx

执行./configure -h命令可以看到类似如下的内容,说明sphinx已经配置生效了。

...

...

...

 === Sphinx Storage Engine ===

  Plugin Name:      sphinx

  Description:      Sphinx Storage Engines

  Supports build:   static and dynamic

  Configurations:   max, max-no-ndb

make && make install

mysql安装完成以后,启动mysql服务,用命令行登录mysql,输入show engines,会出现sphinx存储引擎,要的就是这个效果。

mysql> show engines;

+------------+---------+-----------------------------------------------------------+--------------+------+------------+

| Engine     | Support | Comment                                                   |
Transactions | XA   | Savepoints |

+------------+---------+-----------------------------------------------------------+--------------+------+------------+

| CSV        | YES     | CSV storage engine                                        |
NO           | NO   | NO         |

| SPHINX     | YES     | Sphinx storage engine 0.9.8                               |
NO           | NO   | NO         |

| MEMORY     | YES     | Hash based, stored in memory, useful for temporary tables | NO           | NO   |
NO         |

| MyISAM     | DEFAULT | Default engine as of MySQL 3.23 with great performance    | NO           | NO   | NO         |

| MRG_MYISAM | YES     | Collection of identical MyISAM tables          
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: