一.安装 coreseek
1.mmseg安装
cd coreseek/mmseg中
./configure --prefix=/usr/local/mmseg
注:执行后有
config.status:error:cannont find input file: src/Makefile.in
用automake命令来执行一次
然后在执行一下
./configure --prefix=/usr/local/mmseg
后
make && make install
2.coreseek安装
cd coreseek/csft中
./configure --prefix=/usr/local/coreseek \
--with-mysql=/usr/local/mysql \ 连MYSQL
--with-mmseg=/usr/local/mmseg \ 中文分词连
--with-mmseg-includes=/usr/local/mmseg/include/mmseg/ \
--with-mmseg-libs=/usr/local/mmseg/lib/
make && make install
二.配置
cp /usr/local/coreseek/etc/sphinx.conf.dist csft.conf
修改
增加这两项
charset_type=zh_cn.utf-8
charset_dictpath=/usr/local/mmseg/etc/
三.增量索引
1.创建一个计数器的表
create table sp_counter(
count_id int unsigned primary key auto_increment,
max_doc_id int unsigned
);
2.再次修改配置文件
vi /usr/local/coreseek/etc/csft.conf
source main{
把sql_query_pre改成下面的语句
sql_query_pre=replace into sp_counter select 1,max(id) from t1[表]
sql_query = select id,title,content from t1 where id<=(select max_doc_id from sp_counter where count_id=1)
在增量索引段修改
source delta : main{
sql_query_pre = set names utf8
sql_query=select id,title,content from t1 where id>(select max_doc_id from sp_counter where count_id=1)
}
index delta : main{
source = delta
path = /usr/local/coreseek/var/data/delta
morphology = stem_en
}
3.测试
建立索引
./indexer main --rotate 主索引
./indexer delta --rotate 增量索引
4.添加计划任务
vi main.sh
#!/bin/bash
#main.sh
/usr/local/coreseek/bin/indexer main --rotate >>/log/main.log
vi delate.sh
#!/bin/bash
#delate.sh
/usr/local/coreseek/bin/indexer delate --rotate >>/log/delate.log
最后,每5分钟执行一次增量索引和凌晨2:30重新建立主索引
*/5 * * * * /usr/local/coreseek/etc/delate.sh
30 2 * * * /usr/local/coreseek/etc/main.sh
与PHP测试
<?php header('Content-Type:text/html;charset=UTF-8'); echo '<h1>搜索显示页</h1>'; $key = $_POST['key']; $sphinx = new SphinxClient(); $sphinx->SetServer('localhost',9312); $sphinx->SetMatchMode(SPH_MATCH_ANY); //$sphinx->SetLimits(0,0); $res = $sphinx->query("$key","*"); //print_r($res); $option = array( "before_match"=>'<font style="color:red;font-weight:bold;">', "after_match"=>'</font>' ); $id = implode(',',array_keys($res['matches'])); $sql = "select id,title,content from t1 where id in ({$id})"; $rst = mysql_query($sql); while($row = mysql_fetch_assoc($rst)){ $rst2 = $sphinx->buildExcerpts($ros,"main",$key,$option); } ?>
##################################################################
-- sphinx安装
tar zxvf sphinx.tar.gz
cd sphinx
./configure --prefix=/usr/local/sphinx --with-mysql=/usr/local/mysql/
make && make install
--配置
cd /usr/local/sphinx中
cd etc/
cp sphinx.conf.dist sphinx.conf
vi sphinx.conf
--创建索引命令:indexer
-c 指定配置文件
--all 对所有索引重新编制索引
--rotate 用于轮换索引,主要是再不停止服务的时候,增加索引
--merge 合并索引
./indexder -c /usr/local/sphinx/etc/shpinx.conf --all
执行的时候报错
cp /usr/local/mysql/lib/mysql/libmysqlclient.so.16 /usr/lib/
这样就可以解决了,就可以执行了
--------------------------------------------------------------------
--coreseek安装
1.下载 http://www.coreseek.cn官网去下载
2.安装
tar zxvf coreseek.tar.gz
cd mmseg目录中 [中文分词目录]
automake
###############################
aclocal
libtoolize --force
automake --add-missing
autoconf
autoheader
make clean
###############################
./configure --prefix=/usr/local/mmseg
make && make install
进行coreseek/csft目录中
./configure --prefix=/usr/local/coreseek --with-mysql=/usr/local/mysql --with-mmseg=/usr/local/mmseg --with-mmseg-includes=/usr/local/mmseg/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg/lib/
make && make install
--配置
cd /usr/local/coreseek/etc
cp sphinx.conf.dist csft.conf
vi csft.conf
修改的地方
index test1{
添加下面两行
charset_type=zh_cn.utf-8
charset_dictpath=/usr/local/mmseg/etc/ # 安装mmseg的目录
}
-- 启动coreseek服务
/usr/local/coreseek/bin/searchd
-c # 指定配置文件
--stop # 停目服务
--pidfile # 用来显式指定一个PID文件
-p # 指定端口
#/usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/csft.conf
-- 安装sphix支持PHP模块
1.安装coreseek目录中 api/libsphinxclient中的软件
./configure
make && make install
2.下载sphinx支持的PHP模块
http://pecl.php.net/get/sphinx-1.3.0.tgz
tar zxf sphinx-1.3.0.tgz
cd sphinx-1.3.0中
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-sphinx
make && make install
3.修改PHP.INI文件
添加
extension=sphinx.so
4.重启apache生效
##################################
--coreseek安装
1.官网下载:http://www.coreseek.cn/ 对应的版本
2.安装
wget http://www.coreseek.cn/uploads/csft/3.2/coreseek-3.2.14.tar.gz
tar zxf coreseek-3.2.14.tar.gz
cd coreseek-3.2.14
先安装一下需要的支持软件包
yum -y install make gcc gcc++ gcc-c++ libtool autoconf automake imake mysql-devel libxml2-devel expat-devel
cd mmseg-3.2.14 # 中文分词的词库目录要先安装
./bootstrap 测试系统的环境的
在没有报错的情况进行下面操作
./configure --prefix=/usr/local/mmseg
make && make install
cd /usr/local/mmseg/bin
./mmseg -d /usr/local/mmseg/etc 源码包/mmseg-3.2.14/src/t1.txt
安装csft-4.1包中
cd csft-4.1
sh buildconf.sh #检查环境,不报错就可以进行下一步
./configure --prefix=/usr/local/coreseek --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/mmseg/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg/lib/ --with-mysql
make && make install
cd /usr/local/coreseek
cd etc/sphinx.conf.dist etc/csft.conf
-- 安装sphix支持PHP模块
1.安装coreseek目录中 api/libsphinxclient中的软件
./configure
make && make install
2.下载sphinx支持的PHP模块
http://pecl.php.net/get/sphinx-1.3.0.tgz
tar zxf sphinx-1.3.0.tgz
cd sphinx-1.3.0中
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-sphinx
make && make install
3.修改PHP.INI文件
添加
extension=sphinx.so
4.重启apache生效
注:要学习的 不懂的到官网看中文手册学习
3.2. 属性
3.7. SQL 数据源 (MySQL, PostgreSQL) ---> 区段查询