coreseek 安装及使用方法详解

coreseek 安装及使用

一般站点都需要搜索功能,如果是php+mysql站点,建议选择coreseek,如果是java站点建议使用lucene,coreseek 是一款很好的中文全文检索/搜索软件,支持高速建立索引、有很强的扩展性、支持分布式检索,支持不同的搜索模式(’完全匹配’,’短语匹配’,’任一匹配’)。

logo1

如果下面的过程遇到问题,请参考 coreseek安装遇到的错误和问题解决方案 我把安装和配置遇到的常见问题和解决办法都总结在那里了。

一、coreseek 安装

1:安装mmseg分词库

wget http://www.coreseek.cn/uploads/csft/4.0/coreseek-3.2.14-beta.tar.gz
tar -zxvf coreseek-3.2.14-beta.tar.gz
cd coreseek-3.2.14-beta
cd mmseg-3.2.14
./bootstrap
./configure –prefix=/usr/local/mmseg3 #配置安装目录
make
make install
cd ..

2:安装coreseek

cd csft-3.2.14
sh buildconf.sh
./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=/usr/local/mysql
make
make install
cd..

3:测试mmseg分词和coreseek检索

cd /usr/local/src/coreseek-3.2.14
cd testpack
cat var/test/test.xml    #现实的是中文的内容
/usr/local/mmseg3/bin/mmseg -d /usr/local/mmseg3/etc var/test/test.xml #显示xml文件内容
/usr/local/coreseek/bin/indexer -c etc/csft.conf –all #建立索引
/usr/local/coreseek/bin/search -c etc/csft.conf # 进行搜索

二、coreseek配置和使用

1:配置example.conf文件

cd /usr/local/coreseek/etc
cp sphinx-min.conf.dist example.conf

对example.conf的配置进行改造,变成我们所需的配置文件。

source example
{
type                    = mysql
sql_host                = localhost
sql_user                = ***
sql_pass                = ***
sql_db                    = ***
sql_port                = 3306
sql_sock            = /tmp/mysql.sock
sql_query_pre            = SET NAMES utf8
sql_query                = SELECT id,content FROM table_name #不管表的主键叫什么,查出来的结果都是为id
sql_query_info_pre      = SET NAMES utf8                      #命令行查询时,设置正确的字符集
sql_query_info          = SELECT * FROM table WHERE id=$id  LIMIT 100#命令行查询时,从数据库读取原始数据信息
}

#index定义
index example
{
source            = example             #对应的source名称
path            = /usr/local/coreseek/var/data/example/ #请修改为实际使用的绝对路径
docinfo            = extern
mlock            = 0
morphology        = none
min_word_len        = 1
html_strip                = 0

#中文分词配置,详情请查看:http://www.coreseek.cn/products-install/coreseek_mmseg/
charset_dictpath = /usr/local/mmseg3/etc/ #BSD、Linux环境下设置,/符号结尾
#charset_dictpath = etc/  #Windows环境下设置,/符号结尾,最好给出绝对路径,
charset_type        = zh_cn.utf-8
}

#全局index定义
indexer
{
mem_limit            = 128M
}

#searchd服务定义
searchd
{
listen                  =   9312
read_timeout        = 5
max_children        = 60
max_matches            = 1000
seamless_rotate        = 0
preopen_indexes        = 0
unlink_old            = 1
pid_file = /usr/local/coreseek/var/log/searchd_example.pid  #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/…
log = /usr/local/coreseek/var/log/searchd_example.log  #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/…
query_log = /usr/local/coreseek/var/log/query_example.log #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/…
}

2:开启searchd服务 (这点很重要)

coreseek刚安装后searchd服务是没开启的,需要先开启,不然创建索引的时候会出错。

先在 /usr/local/src/coreseek/var/log下创建一个searchd_example.pid文件,然后执行下面的代码:

/usr/local/coreseek/bin/searchd –config /usr/local/coreseek/etc/example.conf

3:创建索引

/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/example.conf –all –rotate

出现下面的提示:

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 ‘/usr/local/coreseek/etc/example.conf’…
indexing index ‘example’…
collected 1 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 1 docs, 631 bytes
total 0.005 sec, 118854 bytes/sec, 188.35 docs/sec
total 1 reads, 0.000 sec, 0.8 kb/call avg, 0.0 msec/call avg
total 5 writes, 0.000 sec, 0.5 kb/call avg, 0.0 msec/call avg
rotating indices: succesfully sent SIGHUP to searchd (pid=14094).
说明coreseek已经可以使用了。
可以把创建索引的命令写入crontab里面进行定时,实时更新索引。

4:php 和 coreseek 结合进行查询

先下载sphinxapi,然后文件引入结合php进行查询,下面更多参数的详解和配置,可以参考 coreseek api php手册

 

require_once(‘sphinxapi’);
s=newSphinxClient();s=newSphinxClient();s->SetServer(‘127.0.0.1′,’9312’); //设置searchd的主机名和TCP端口
s>SetConnectTimeout(1);//s−>SetConnectTimeout(1);//设置连接超时s->SetMatchMode(SPH_MATCH_BOOLEAN); //设置全文查询的匹配模式
pagesize=20;//pagesize=20;//自己定义的页数s->SetLimits(start,start,page_size); //设置返回结果集偏移量和数目
s>SetSortMode(SPHSORTEXTENDED,goodcountDESC,@idDESC);//s−>SetSortMode(SPHSORTEXTENDED,”goodcountDESC,@idDESC”);//设置排序s->SetArrayResult(true);//控制搜索结果集的返回格式
res=res=s->Query(keyword,);//keyword,′∗′);//执行搜索查询res_list = $res[‘matches’];

安装遇到的错误和问题解决方案

1、测试mmseg分词的时候

执行

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

提示下面的错误:

/usr/local/coreseek/bin/indexer: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory

原因:sphinx indexer的依赖库ibmysqlclient.so.18找不到。

解决办法:

vi /etc/ld.so.conf
加入 /usr/local/mysql/lib

然后运行 ldconfig

问题解决

2、执行索引的时候

/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_ttd_search.conf –all –rotate

提示下面的错误:

FATAL: failed to open /usr/local/coreseek/var/data/ttd_article/.tmp.spl: No such file or directory, will not index. Try –rotate option.

原因:source源找不到mysql.sock

解决办法:在配置文件csft_ttd_search.conf(自己创建的文件)的 source源 加入下面的代码

sql_sock   = /tmp/mysql.sock

3、执行索引的时候,出现的警告,导致索引没创建成功

WARNING: failed to open pid_file ‘/usr/local/coreseek/var/log/searchd_ttd_search.pid’.
WARNING: indices NOT rotated.

原因:找不到searchd_ttd_search.pid文件

解决办法:在’/usr/local/coreseek/var/log 下创建searchd_ttd_search.pid文件

再执行/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_ttd_search.conf –all –rotate
出现了另外一个警告:

WARNING: failed to scanf pid from pid_file ‘/usr/local/coreseek/var/log/searchd_ttd_search.pid’.
WARNING: indices NOT rotated.

原因:虽然创建了searchd_ttd_search.pid文件,但是里面没有写入进程id

解决办法(根本原因):在执行索引之前没有启动searchd服务,因此执行下面的命令

/usr/local/coreseek/bin/searchd –config /usr/local/coreseek/etc/ttd_search.conf

出现了期待已久的成功提示:

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 ‘/usr/local/coreseek/etc/ttd_search.conf’…
listening on all interfaces, port=9312
rotating index ‘mysql’: success

声明:本站资源绿色无后门无广告,可放心下载。如无特殊说明或标注,均为本站原创发布,转载请注明出处!