中文全文检索之coreseek(一)

一、安装

       关于coreseek的相关介绍,可通过网址:http://www.coreseek.cn 学些。下面直接进入主题。
       1、解压 
            #tar -zxvf coreseek-4.1-beta.tar.gz 

             #cd coreseek-4.1-beta

       2、安装中文分词包

             进入中文分词安装目录

             #cd mmseg-3.2.14/

             安装中文分词包,我的路径是/share_folder/source/sphinx/mmseg/  

             # ./configure --prefix=/share_folder/source/sphinx/mmseg/

             #make && make install

             注意,在./configure的时候,可能会报:

                  config.status: error: cannot find input file: src/Makefile.in

             直接运行如下命令(系统中如果没有automake工具,得安装):

             #automake

             再次运行./configure 即可进行配置了,安装好后,进入安装目录的bin目录下,可运行

             mmseg文件。

        3、把sphinxcoreseek中文分词包结合起来

              进入sphinx目录

              #cd /share_folder/source/sphinx/coreseek-4.1-beta/csft-4.1

              #./configure --prefix=/share_folder/source/sphinx/csft/   \

                 --with-mmseg=/share_folder/source/sphinx/mmseg/bin/  \

                 --with-mmseg-includes=/share_folder/source/sphinx/mmseg/include/mmseg  \

                 --with-mmseg-libs=/share_folder/source/sphinx/mmseg/lib/

              #make && make install

  二、生成数据源

          coreseek自带用于mysql测试的数据库表数据,在csft安装的etc目录下(example.sql)

          运行如下命令:

          #mysql -u root < /share_folder/source/sphinx/csft/etc/example.sql

          在mysql数据库(test)的表documents中将生成测试用数据,可以用sql语句去数据库

          中进行查询。

  三、coreseek配置文件csft.conf配置

         1、拷贝配置文件,coreseek中的默认配置文件名是csft.conf

                #cp /share_folder/source/sphinx/csft/etc/sphinx.conf.dist  csft.conf

          2、配置支持中文分词,此处只写出更改的配置。

                该配置文件中,主要由4个部分组成:

                sourece  --------------------配置数据源

                index    --------------------配置索引

                indexer  --------------------配置索引内存相关

                searchd  --------------------配置索引服务器 

               在index部分:

               #stopwords                      = G:\data\stopwords.txt

               #wordforms                      = G:\data\wordforms.txt

               #exceptions             = /data/exceptions.txt 

               #支持中文分词

               charset_type =zh_cn.utf-8

               #安装中文分词的路径

              charset_dictpath        =/share_folder/source/sphinx/mmseg/etc/

四、生成索引

        安装好源码后,在sphinx安装目录下(/share_folder/source/sphinx/csft/bin),有3个工具 

文件:

        indexer  -------------------------生成索引命令

        search  --------------------------测试查询命令

        searchd --------------------------搜索引擎服务器,测试api的时候,需要启动这个命令

         1、建立索引

               #cd /share_folder/source/sphinx/csft/bin

               #./indexer test1

              生成索引的时候报:

              ./indexer: error while loading shared libraries: libmysqlclient.so.15: cannot open shared  \

               object file: No such file or directory

              这主要是因为你安装了一些库后,没有能够配置相应的环境变量,可以通过连接的

        式修正这个问题。

               2、测试搜索
                     #./search test   (搜索关键字 test)

                     不出错的话,将得到如下结果:

                     [root@localhost bin]# ./search test

                     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 '/share_folder/source/sphinx/csft/etc/csft.conf'...

                     index 'test1': query 'test ': returned 3 matches of 3 total in 0.030 sec

                     displaying matches:

                    1. document=1, weight=2, group_id=1, date_added=Sun Feb 24 02:23:37 2013

                          id=1

                         group_id=1

                         group_id2=5

                         date_added=2013-02-24 02:23:37

                         title=test one          

                     content=this is my test document number one. also checking search within phrases.

                     。。。。。。         

                    words:

                     1. 'test': 3 documents, 5 hits

                     index 'test1stemmed': query 'test ': returned 3 matches of 3 total in 0.002 sec

                     displaying matches:

                    1. document=1, weight=2, group_id=1, date_added=Sun Feb 24 02:23:37 2013

                                         id=1

                                         group_id=1

                                         group_id2=5

                                         date_added=2013-02-24 02:23:37

                                         title=test one

                                        content=this is my test document number one. also checking search within phrases.

                    2. document=2, weight=2, group_id=1, date_added=Sun Feb 24 02:23:37 2013

                     。。。。。。

                    words:

                             1. 'test': 3 documents, 5 hits

           3、  Api测试
                   源码中自带了几个版本的api,包括phpjavac语言等api。下面仅以c语言api

           为例。进入/coreseek-3.2.14/csft-3.2.14/目录,里面有个api文件夹,libsphinxclient即是

           c语言api。编译api

                   #cd libsphinxclient

                   #./configure

                   #make

                  编译完后,将在该目录下生成可执行文件testtest.c中是查询关键字test。可在

                  test_query函数中修改。执行查询前,先启动搜索服务器swarchd

                  #/share_folder/source/sphinx/csft/bin/searchd  (加上 --stop将停止该服务)

                   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 '/share_folder/source/sphinx/csft/etc/csft.conf'...

                   listening on all interfaces, port=9312 

                 然后运行可执行文件test,不出错的话,将显示查询结果。查询的时候,报:

                          ERROR connection to localhost failed (errno=111, msg=Connection

                 我的是没有把localhost127.0.0.1映射起来,所以会报这个错,如下命令可修正。 

                       #echo "127.0.0.1 `hostname` localhost localhost.localdomain" >/etc/hosts

             以上,简单测试结束。

   

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值