1:首先安装coreseek
wget http://www.coreseek.cn/uploads/csft/4.0/coreseek-4.1-beta.tar.gz tar -zxvf coreseek-4.1-beta.tar.gz yum -y install gcc gcc-c++ libtool autoconf automake imake mysql-devel libxml2-devel expat-devel cd coreseek-4.1-beta cd mmseg-3.2.14 ./bootstrap ./configure --prefix=/usr/local/mmseg3.2.14 make make install cd .. cd csft-4.1 sh buildconf.sh #如果sh buildconf.sh最后没有生成configure脚本,且提示automake: warnings are treated as errors,可以将configure.ac中的这行 AM_INIT_AUTOMAKE([-Wall -Werror foreign]) 修改为 AM_INIT_AUTOMAKE([-Wall foreign]) ./configure --prefix=/usr/local/coreseek4.1 --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/mmseg3.2.14/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg3.2.14/lib/ --with-mysql make make install
常见错误文章见:https://www.mawenbao.com/note/sphinx-coreseek-summary.html
2:索引配置文件大致如下:
source test { type = mysql sql_host = 127.0.0.1 sql_user = test sql_pass = 123456 sql_db = test sql_port = 3306 sql_query_pre = SET NAMES utf8 sql_query_pre = REPLACE INTO sphinx_counter SELECT 1, MAX(id) FROM news sql_query_range = SELECT MIN(id),MAX(id) FROM news sql_range_step = 10000 sql_ranged_throttle = 1000 sql_query = SELECT id,author_id,title,content FROM news where id>=$start AND id<=$end sql_attr_uint = author_id sql_query_info_pre = SET NAMES utf8 sql_query_info = SELECT * FROM news WHERE id=$id } source extend : test { sql_query_pre = SET NAMES utf8 sql_query_range = sql_range_step = 0 sql_query = SELECT id,author_id,title,content FROM news WHERE id > ( SELECT max_doc_id FROM sphinx_counter WHERE counter_id=2 ) } index test { source = test path = /usr/local/coreseek4.1/data/test docinfo = extern mlock = 0 morphology = none min_word_len = 1 html_strip = 0 charset_dictpath = /usr/local/mmseg3.2.14/etc/ charset_type = zh_cn.utf-8 } index extend : test { source = extend path = /usr/local/coreseek4.1/data/extend docinfo = extern mlock = 0 morphology = none min_word_len = 1 html_strip = 0 charset_dictpath = /usr/local/mmseg3.2.14/etc/ charset_type = zh_cn.utf-8 } indexer { mem_limit = 2000M } searchd { listen = 127.0.0.1:9312 listen = 127.0.0.1:9313:mysql41 read_timeout = 10 max_children = 0 max_matches = 5000 seamless_rotate = 0 preopen_indexes = 0 unlink_old = 1 pid_file = /usr/local/coreseek4.1/log/searchd_mysql.pid log = /usr/local/coreseek4.1/log/searchd_mysql.log query_log = /usr/local/coreseek4.1/log/query_mysql.log }
3:建立索引和启动服务
/usr/local/coreseek4.1/bin/indexer --all -c /usr/local/coreseek4.1/test.conf /usr/local/coreseek4.1/bin/searchd -c /usr/local/coreseek4.1/test.conf
4:设置任务来定时重建主索引和增量索引
#test.sh主索引shell(* */3 * * * /usr/local/coreseek4.1/test.sh)
#!/bin/bash date=`date "+%Y-%m-%d %H:%M:%S"` echo -e "$date--start\n" /usr/local/coreseek4.1/bin/indexer test --rotate -c /usr/local/coreseek4.1/test.conf date=`date "+%Y-%m-%d %H:%M:%S"` echo -e "$date--end\n"
#extend.sh增量索引shell(*/10 * * * * /usr/local/coreseek4.1/extend.sh)
#!/bin/bash date=`date "+%Y-%m-%d %H:%M:%S"` echo -e "$date--start\n" /usr/local/coreseek4.1/bin/indexer extend --rotate -c /usr/local/coreseek4.1/test.conf date=`date "+%Y-%m-%d %H:%M:%S"` echo -e "$date--end\n"
这样我们就完成了一个基本的搜索服务,同时为了避免程序意外退出,你也可以写个检查任务来自动启动coreseek服务.