8-18 4,682 views
"一"
3.2下载地址:coreseek-3.2.14
4.1下载地址:coreseek-4.1-beta.tar
"二"
"三"
然后 #~ cd cd mmseg-3.2.14/
执行命令
#~ ./bootstrap
#~ ./configure --prefix=/usr/local/mmseg
#~ make
#~ make install
"四"
~# ./configure --prefix=/usr/local/coreseek --with-mysql-includes=/usr/include/mysql --with-mysql-libs=/usr/lib64/mysql/ --with-mmseg=/usr/local/mmseg --with-mmseg-includes=/usr/local/mmseg/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg/lib/
~# make
~# make install
注解,如果无法安装,出现error: ‘ExprEval’ was not declared in 。 请打补丁
补丁下载:sphinxexpr.cpp.patch
参考 : http://ju.outofmemory.cn/entry/102163
注解2:如安装4.1版本出现问题。请参考 http://blog.csdn.net/jcjc918/article/details/39032689
在csft-3.2.14下面执行#~ patch -p0 < /sphinx/sphinxexpr.cpp-csft-3.2.14-beta.patch
再次执行 #~ make && make install
还有问题的话,修改
原因是g++没有添加 -libiconv选项
cd sphinx-2.1.9-release
vi src/MakeFile
把LIBS = -lm -lz -lexpat -L/usr/local/lib -lrt -lpthread
改成
LIBS = -lm -lz -lexpat -L/usr/local/lib -lrt -lpthread -liconv
即可。
编辑sphinxexpr.cpp
将所有的:
T val = ExprEval ( this->m_pArg, tMatch );
替换成
T val = this->ExprEval ( this->m_pArg, tMatch );
"五、安装php
首先安装libsphinxclient。 它在coreseek-3.2.14-beta/csft-3.2.14/api/libsphinxclient/里面能找到。、
执行命令~ ~#./configure
~# make && make install
去http://pecl.php.net/package/sphinx 下载 php-sphinx 扩展 .
~ wget https://pecl.php.net/get/sphinx-1.3.3.tgz #这里我下载的是1.3.3版本
~ tar -xf sphinx-1.3.3.tgz
~ cd sphinx-1.3.3
~ phpize
~ ./configure -with-php-config=/usr/bin/php-config
~ make && make install
安装完成~ 然后添加php扩展
# cd /etc/php.d/
# cp gd.ini sphinx.ini
# vi sphinx.ini
extension=sphinx.so
# service php-fpm restart
"六"
进入mysql , show variables like ‘characterset%’;
如果不是utf8。请更改数据库编码
~ vim /etc/my.conf
~ service mysqld stop
~ 在mysqld下面添加
~ character_set_server=utf8
~ init_connect='SET NAMES utf8'
~ service mysqld start .
查看是否有 /etc/csft.conf, 如果没有
$ cd /usr/local/coreseek/
$ cp etc/sphinx-min.conf.dist /etc/csft.conf
命令行测试mmseg分词,coreseek搜索(需要预先设置好字符集为zh_CN.UTF-8,确保正确显示中文)
$ cd testpack
$ cat var/test/test.xml #此时应该正确显示中文
$ /usr/local/mmseg3/bin/mmseg -d /usr/local/mmseg3/etc var/test/test.xml
$ /usr/local/coreseek/bin/indexer -c /etc/csft.conf --all
$ /usr/local/coreseek/bin/search -c /etc/csft.conf 网络搜索
我的 csft.conf 的配置
source src1
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = 123456
sql_db = test
sql_port = 3306 # optional, default is 3306
sql_query = \
SELECT id,title,content \
FROM documents
sql_query_pre = SET NAMES utf8
sql_query_info = SELECT * FROM documents WHERE id=$id
}
index test1
{
source = src1
path = /usr/local/coreseek/var/data/test1
docinfo = extern
#charset_type = sbcs
charset_dictpath = /usr/local/mmseg/etc/ # 必须 不然不能使用zh_cn.utf-8
charset_type = zh_cn.utf-8
}
indexer
{
mem_limit = 32M
}
searchd
{
port = 9312
listen = 9306:mysql41
log = /usr/local/coreseek/var/log/searchd.log
query_log = /usr/local/coreseek/var/log/query.log
read_timeout = 5
max_children = 30
pid_file = /usr/local/coreseek/var/log/searchd.pid
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 0
unlink_old = 1
}
"记录下一些常用命令"
服务器测试拆词 ~ /usr/local/coreseek/bin/search -c /etc/csft.conf ‘啦啦啦’
启动coreseek(sphinx) : /usr/local/coreseek/bin/searchd -c /etc/csft.conf
关闭:/usr/local/coreseek/bin/searchd -c /etc/csft.conf –stop
合并: /usr/local/coreseek/bin/indexer -c /etc/csft.conf –merge main delta –rotate –merge-dst-range deleted 0 0
增量索引:/usr/local/coreseek/bin/indexer -c /etc/csft_mysql.conf delta –rotate
php 测试示例
<?php
$s = new SphinxClient();
$s->setServer("127.0.0.1", 9312);
$s->setMatchMode(SPH_MATCH_PHRASE);
$s->setMaxQueryTime(30);
$res = $s->query("尺子",'test1'); #[宝马]关键字,[main]数据源source
$err = $s->GetLastError();
var_dump($res);