一,版本介绍
Coreseek 3.2.14 稳定版
Coreseek 4.1 测式版
Coreseek 5 即将发布
二,安装coreseek
注:本文是以centos+mysql做为数据源支持为基础的coreseek安装教程.mysql安装略过.
1,下载coreseek 3.2稳定版,下载其他版本请去官网自行下载
cd /usr/local/src/
wget http://www.coreseek.cn/uploads/csft/3.2/coreseek-3.2.14.tar.gz
tar xzvf coreseek-3.2.14.tar.gz
cd coreseek-3.2.14
安装coreseek之前需要先安装需要预装的软件:yum install make gcc g++ gcc-c++ libtool autoconf automake imake mysql-devel libxml2-devel expat-devel (注:这是centos 64位
其他系统请参考http://www.coreseek.cn/product_install/install_on_bsd_linux/#deps
2,安装mmseg
$ cd mmseg-3.2.14
$ ./bootstrap #输出的warning信息可以忽略,如果出现error则需要解决
$ ./configure --prefix=/usr/local/mmseg
$ make && make install
$ cd ..
##如果提示libtool: unrecognized option `--tag=CC' ,请查看libtool问题解决方案
##安装完成后,mmseg使用的词典和配置文件,将自动安装到/usr/local/mmseg3/etc中
##中文分词测试,如果显示不正常,请检查当前环境下的locale和UTF-8中文字符显示设置
$ /usr/local/mmseg/bin/mmseg -d /usr/local/mmseg/etc src/t1.txt
中文/x 分/x 词/x 测试/x
中国人/x 上海市/x
Word Splite took: 1 ms.
3,安装coreseek
$ cd csft-3.2.14
##执行configure,进行编译配置:
$ 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
三,配置coreseek支持mysql数据源
1.配置csft_mysql.conf
复制mysql配置文件到coreseek安装目录etc/下(比如/usr/local/coreseek/etc/)
cp /usr/local/src/coreseek-3.2.14/testpack/etc/csft_mysql.conf /usr/local/coreseek/etc/
cd /usr/local/coreseek/etc/
vi csft_mysql.conf
下面红色需要自己配置
==============================================================
#源定义
source test
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = xxxx
sql_db = test
sql_port = 3306
sql_query_pre = SET NAMES utf8
sql_query = SELECT id,title,status from test
#sql_query第一列id需为整数
#title、content作为字符串/文本字段,被全文索引
sql_attr_uint = status #从SQL读取到的值必须为整数
#sql_attr_timestamp = date_added #从SQL读取到的值必须为整数,作为时间属性
sql_query_info_pre = SET NAMES utf8 #命令行查询时,设置正确的字符集
sql_query_info = SELECT * FROM test WHERE id=$id #命令行查询时,从数据库读取原始数据信息
}
#index定义
index test
{
source = test #对应的source名称
path = /usr/local/coreseek/var/data/test #请修改为实际使用的绝对路径,例 如:/usr/local/coreseek/var/...
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环境下设置,/符号结尾,最好给出绝对路径,例如:C:/usr/local/coreseek/etc/...
charset_type = zh_cn.utf-8
}
#全局index定义
indexer
{
mem_limit = 128M
}
#searchd服务定义
searchd
{
listen = 9312
read_timeout = 5
max_children = 30
max_matches = 1000
seamless_rotate = 0
preopen_indexes = 0
unlink_old = 1
pid_file = /usr/local/coreseek/var/log/test_mysql.pid #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
log = /usr/local/coreseek/var/log/test_mysql.log #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
query_log = /usr/local/coreseek/var/log/test_mysql.log #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
}
==============================================================
2,建立索引
路经部分需要改成你自己的地址
/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_mysql.conf --all
可能出现的错误
ERROR: index 'phperz': sql_connect: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) (DSN=mysql://root:***@localhost:3306/phperz).
这是因为mysql的sock文件路经不正确导致的.
确认一下你的mysql.sock路经,建立一个软连接,比如
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
四,coreseek+php使用方式
复制安装止录下的/usr/local/src/coreseek-3.2.14/testpack/api/sphinxapi.php文件到你的项目里
你的程序里include sphinxapi.php
php使用方法见/usr/local/src/coreseek-3.2.14/testpack/api/test.php
$wd = trim($_GET['wd']);
require ( "sphinxapi.php" );
$cl = new SphinxClient();
$cl->SetServer('localhost',9312);
$cl->SetConnectTimeout(3);
$cl->SetArrayResult(true);
$cl->SetMatchMode(1);
$cl->SetFilter("status", array(1));
$cl->SetLimits(0, 10);
$res = $cl->Query($wd, "*");
print_r($res);
运行前记得开启搜索服务守护进程
/usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/csft_mysql.conf
五,coreseek日常维护
启动
/usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/csft_mysql.conf
停止
/usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/csft_mysql.conf --stop
建立索引
/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_mysql.conf --all
重建索引
/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_mysql.conf --all --rotate