coreseek实现中文检索服务

主要参考了两篇文章,使用的安装版本为 coreseek-4.1-beta.tar


文章一,原地址为:http://zhan.renren.com/itbegin?gid=3602888498033481671&checked=true

ubuntu-10.04安装环境

coreseek安装需要预装的软件:

shell>apt-get install make gcc g++ automake libtool m4 autoconf mysql-client libmysqlclient15-dev libxml2-dev libexpat1-dev

 

 

一、基础安装:(此时尚不支持MySQL,完成第二步数据源支持后就支持)

 

$ wget www.coreseek.cn/uploads/csft/3.2/coreseek-3.2.14.tar.gz

$ tar -xzvf coreseek-3.2.14.tar.gz

 

##切换到root用户,确保拥有完整的权限来安装软件

$ su root

 

$ cd coreseek-3.2.14

 

##中文测试环境检查:

$  locale

##以下为核心项,localezh_CN.UTF-8,就可以正常显示和输入中文;

##如果不能正常显示中文,则后面的中文测试部分无法正常进行,但不会影响coreseek的实际功能;

LANG=zh_CN.UTF-8

LC_ALL="zh_CN.UTF-8"

 

##确保可以正常显示,否则请检查当前环境的locale配置,以及当前环境或者客户端已设置好支持UTF-8中文字符显示

$ cat testpack/var/test/test.xml

 

##安装coreseek开发的mmseg,为coreseek提供中文分词功能

$ cd mmseg-3.2.14

##ubuntu环境下,需要使用ACLOCAL_FLAGS="-I /usr/share/aclocal" ./bootstrap

$ ./bootstrap

$ ./configure --prefix=/usr/local/mmseg3

$ make && make install

##如果提示libtool: unrecognized option `--tag=CC' ,请查看libtool问题解决方案

##安装完成后,mmseg使用的词典和配置文件,将自动安装到/usr/local/mmseg3/etc

 

##中文分词测试,显示不正常,请检查当前环境下的localeUTF-8中文字符显示设置

$  /usr/local/mmseg3/bin/mmseg -d /usr/local/mmseg3/etc src/t1.txt

    中文/x /x /x 测试/x 

    中国人/x 上海市/x 

Word Splite took: 1 ms.

##安装coreseek

$ cd csft-3.2.14

##执行configure,进行编译配置:

$ sh buildconf.sh

$ ./configure --prefix=/usr/local/coreseek --without-python --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/mmseg3/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg3/lib/ --without-mysql

##注意,如果是coreseek4.x/sphinx1.x版本,请将--without-mysql更改为--with-mysql

$ make && make install

 

##配置测试,测试是否可以正确运行

$ /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/sphinx-min.conf.dist

##以下为正常测试时的提示信息:

    Coreseek Fulltext 3.2 [ Sphinx 0.9.9-release (r2117)]

    Copyright (c) 2007-2010,

    Beijing Choice Software Technologies Inc (http://www.coreseek.com)

 

     using config file '/usr/local/coreseek/etc/sphinx-min.conf.dist'...

    total 0 reads, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg

    total 0 writes, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg

##

##csft-4.0版显示:ERROR: nothing to do.

##

##至此,coreseek基础环境可以正常安装,我们可以开始后续的工作啦。

##注意:基础环境仅支持xml数据源;如需要mysql或者python数据源,请继续按照下面的步骤操作!!!

 

 

二、数据源支持:支持MySQL数据源

 

##ubuntu9/10:

$ apt-get install mysql-client libmysqlclient15-dev   libxml2-dev libexpat1-dev

 

##重新编译安装coreseek,以支持mysql数据源和xml数据源

$ cd csft-3.2.14

$ make clean

$ ./configure --prefix=/usr/local/coreseek  --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/mmseg3/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg3/lib/ --with-mysql

$ make && make install

##如果出现错误提示:“ERROR: cannot find MySQL include files.......To disable MySQL support, use --without-mysql option.“,可按照如下方法处理:

 

##请找到头文件mysql.h所在的目录,一般是/usr/local/mysql/include,请替换为实际的

##请找到库文件libmysqlclient.a所在的目录,一般是/usr/local/mysql/lib,请替换为实际的

##configure参数加上:--with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib,执行后,重新编译安装

 

 

三、coreseek中文全文检索测试

 

$ cd testpack

 

$  /usr/local/coreseek/bin/indexer -c etc/csft.conf --all

##正常索引全部数据:(csft-4.0版类似)

 

/usr/local/coreseek/bin/search -c etc/csft.conf -a 服务

##以下为正常测试搜索关键词"服务"的数据

Coreseek Fulltext 3.2 [ Sphinx 0.9.9-release (r2117)]

Copyright (c) 2007-2011,

Beijing Choice Software Technologies Inc (http://www.coreseek.com)

 

 using config file 'etc/csft.conf'...

index 'xml': query '服务 ': returned 1 matches of 1 total in 0.015 sec

 

displaying matches:

1. document=3, weight=1, published=Wed Mar 31 21:01:00 2010, author_id=2

 

words:

1. '服务': 1 documents, 1 hits

 

 

 

$  /usr/local/coreseek/bin/searchd -c etc/csft.conf

##以下为正常开启搜索服务时的提示信息:(csft-4.0版类似)

    Coreseek Fulltext 3.2 [ Sphinx 0.9.9-release (r2117)]

    Copyright (c) 2007-2010,

    Beijing Choice Software Technologies Inc (http://www.coreseek.com)

 

    using config file 'etc/csft.conf'...

    listening on all interfaces, port=9312

##如要停止搜索服务/usr/local/coreseek/bin/searchd -c etc/csft.conf --stop

##如要已启动服务,要更新索引/usr/local/coreseek/bin/indexer -c etc/csft.conf --all --rotate

 

##然后,请参考csft-3.2.14api目录中的相关文件,使用PHPPythonRubyJava来测试搜索服务;也可以前往< a href="/products-install/step_by_step/">搜索服务建立三步曲,查看第三步使用PHP测试。

 

 

源码包内容说明:

目录说明:

csft-x.y.zcoreseek源代码

mmseg-i.j.kmmseg源代码

testpack:测试配置和数据包

 

testpack测试说明:

目录说明:

apiapi接口和测试脚本

etc:配置文件

etc/pysourcepython数据源脚本

var:运行数据

var/data:索引文件

var/log:搜索日志

var/test:测试源数据

 

csft 通用测试:(3.2.x4.x均支持)

配置1

    测试对象:xml数据源,中文分词与搜索

    对应配置:etc/csft.conf

    测试数据:var/test/test.xml

    PHP程序:api/test_coreseek.php

    在线说明:http://www.coreseek.cn/products-install/install_on_bsd_linux/

 

配置2

    测试对象:xml数据源,单字切分与搜索

    对应配置:etc/csft_cjk.conf

    测试数据:var/test/test.xml

    PHP程序:api/test_coreseek.php

    在线说明:http://www.coreseek.cn/products-install/ngram_len_cjk/

 

配置3

    测试对象:mysql数据源,中文分词与搜索

    对应配置:etc/csft_mysql.conf

    测试数据:var/test/documents.sql

    PHP程序:api/test_coreseek.php

    测试说明:请先将测试数据导入数据库,并设置好配置文件中的MySQL用户密码数据库

    在线说明:http://www.coreseek.cn/products-install/mysql/

 

配置4

    测试对象:python数据源,中文分词与搜索

    对应配置:etc/csft_demo_python.conf

    数据脚本:etc/pysource/csft_demo/__init__.py

    PHP程序:api/test_coreseek.php

    测试说明:请先安装Python 2.6 (x86)

    在线说明:http://www.coreseek.cn/products-install/python/

 

配置5

    测试对象:python+mssql数据源,中文分词与搜索

    对应配置:etc/csft_demo_python_pymssql.conf

    数据脚本:etc/pysource/csft_demo_pymssql/__init__.py

    PHP程序:api/test_coreseek.php

    测试说明:请先安装Python 2.6 (x86)pymssqlpy2.6

    在线说明:http://www.coreseek.cn/products-install/python/

 

coreseek-4.y.z 新增测试:

配置6

    测试对象:RT实时索引,中文分词与搜索

    对应配置:etc/csft_rtindex.conf

    PHP程序:api/test_coreseek_rtindex.php

    在线说明:http://www.coreseek.cn/products-install/rt-indexes/

    

配置7

    测试对象:RT实时索引,单字切分与搜索

    对应配置:etc/csft_rtindex_cjk.conf

    PHP程序:api/test_coreseek_rtindex.php

    在线说明:http://www.coreseek.cn/products-install/rt-indexes/



文章二,原地址为:http://blog.csdn.net/jcjc918/article/details/39032689

主要解决了无法生成configue文件的问题

之前在安装 coorseek 的时候,遇到了一些错误,在官网根本看不到解决方案,最后 google 在一个大牛博客的评论区找到了解决方法,顿时把膝盖献上去了~~

     整理到这里是为了方便一些人找到,长城防火墙毕竟让 google 不是那么友好了 %>_<% 不过大牛的博客还是上得了的:传送门


     错误现象:执行 buildconf.sh 报错,无法生成configure文件

     提示的主要错误为:

[plain] view plain copy
 print?
  1. libstemmer_c/mkinc.mak:10: warning: source file 'runtime/utilities.c' is in a subdirectory,  
  2. libstemmer_c/mkinc.mak:10: but option 'subdir-objects' is disabled  
  3. libstemmer_c/Makefile.am:3: 'libstemmer_c/mkinc.mak' included from here  
  4. libstemmer_c/mkinc.mak:10: warning: source file 'libstemmer/libstemmer.c' is in a subdirectory,  
  5. libstemmer_c/mkinc.mak:10: but option 'subdir-objects' is disabled  
  6. libstemmer_c/Makefile.am:3: 'libstemmer_c/mkinc.mak' included from here  
  7. /usr/local/share/automake-1.14/am/library.am: warning: 'libstemmer.a': linking libraries using a non-POSIX  
  8. /usr/local/share/automake-1.14/am/library.am: archiver requires 'AM_PROG_AR' in 'configure.ac'  
  9. libstemmer_c/Makefile.am:2: while processing library 'libstemmer.a'  
  10. /usr/local/share/automake-1.14/am/library.am: warning: 'libsphinx.a': linking libraries using a non-POSIX  
  11. /usr/local/share/automake-1.14/am/library.am: archiver requires 'AM_PROG_AR' in 'configure.ac'  
  12. src/Makefile.am:14: while processing library 'libsphinx.a'  

       看起来非常多其实就是两个:1.but option 'subdir-objects' is disabled    2. archiver requires 'AM_PROG_AR' in 'configure.ac'


     解决方案:

     1. 在 csft-4.1/buildconf.sh 文件中,查找

[plain] view plain copy
 print?
  1. && aclocal \  

     后加上

[plain] view plain copy
 print?
  1. && automake --add-missing \  

     2. 在 csft-4.1/configure.ac 文件中,查找:
[plain] view plain copy
 print?
  1. AM_INIT_AUTOMAKE([-Wall -Werror foreign])  
     改为:
[plain] view plain copy
 print?
  1. AM_INIT_AUTOMAKE([-Wall foreign])  

     查找:
[plain] view plain copy
 print?
  1. AC_PROG_RANLIB   
     后面加上
[plain] view plain copy
 print?
  1. AM_PROG_AR  

      3. 最后,在 csft-4.1/src/sphinxexpr.cpp 文件中, 替换所有:
[plain] view plain copy
 print?
  1. T val = ExprEval ( this->m_pArg, tMatch );  
      成为:
[plain] view plain copy
 print?
  1. T val = this->ExprEval ( this->m_pArg, tMatch );  

文章三,解决mysql中文编码问题

MySQL中文显示乱码或者问号是因为选用的编码不对或者编码不一致造成的,最简单的方法就是修改mysql的配置文件my.cnf。在[mydqld]和[client]段加入

default-character-set=utf8

(有的版本不支持default-character-set=utf8,用character_set_server=utf8来取代 default-character-set=utf8即可)

注:如果没有[client]就手工加入[client]段

( 5.0以上版本修改方法:

修改/etc/my.cnf 中的设置, 
     在[client]节点下添加  
       default-character-set=utf8 
    在[mysqld]节点下添加 
       character-set-server=utf8 
      collation-server=utf8_general_ci 

)

然后重启mysql即可

附关闭启动命令:(

[root@sg211 mysql-cluster]# bin/mysqladmin -u root -p shutdown;

[root@sg211 mysql-cluster]# bin/mysqld_safe --defaults-file=/opt/mysql-cluster/etc/my.cnf --basedir=/opt/mysql-cluster --datadir=/opt/mysql-cluster/data --user=mysql &


这时可以验证下是否生效

mysql> show variables like 'char%';
+--------------------------+------------------------------------------+
| Variable_name | Value |
+--------------------------+------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /opt/mysql-cluster/share/mysql/charsets/ |
+--------------------------+------------------------------------------+
8 rows in set (0.00 sec)

可以 看出都已经更正为utf8了,这样新建立的数据库缺省就是UTF8编码了。

那么已经创建好的数据库及库中的表要如何更改为utf8呢?

用alter语句(修改数据库的字符集不会改变原有数据表的字符集)

utf8:
ALTER DATABASE `数据库` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci 

ALTER TABLE `数据表` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci

gbk (包含gb2312):

ALTER DATABASE `数据库` DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci

ALTER TABLE `数据表` DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值