先建立一张增量索引记录表pre_coreseek(id,maxid)
###配置文件
vim /etc/mysql.conf
#MySQL数据源配置,详情请查看:http://www.coreseek.cn/products-install/mysql/
#请先将var/test/documents.sql导入数据库,并配置好以下的MySQL用户密码数据库
#源定义
source mysql
{
type = mysql
sql_host = 192.168.1.180
sql_user = root
sql_pass = 1
sql_db = btbbs
sql_port = 3306
sql_query_pre = SET NAMES utf8
sql_query_pre = REPLACE INTO pre_coreseek SELECT 1,MAX(pid) from pre_forum_post
sql_query = SELECT p.pid,p.tid,p.fid,p.dateline,p.authorid, p.subject,p.message,t.digest,t.displayorder,t.lastpost,t.special FROM pre_forum_post AS p LEFT JOIN pre_forum_thread AS t USING(tid) WHERE pid <=(SELECT maxid FROM pre_coreseek WHERE id=1)
#sql_query第一列pid需为整数且唯一值 subject.message作为字符串/文本字段,被全文索引,查询关键字最好大写可以避免一些不必要错误
sql_attr_uint = tid #从SQL读取到的值必须为整数,过滤模式
sql_attr_uint = fid #从SQL读取到的值必须为整数,过滤模式
sql_attr_uint = digest #从SQL读取到的值必须为整数,过滤模式
sql_attr_uint = displayorder #从SQL读取到的值必须为整数,过滤模式
sql_attr_uint = authorid #从SQL读取到的值必须为整数,过滤模式
sql_attr_uint = special #从SQL读取到的值必须为整数,过滤模式
sql_attr_timestamp =lastpost #从SQL读取到的值必须为整数,作为时间属性
#sql_query_info_pre = SET NAMES utf8 #命令行查询时,设置正确的字符集
#sql_query_info = SELECT tid, fid, dateline, subject,author,authorid FROM pre_forum_thread WHERE tid=$id #命令行查询时,从数据库读取原始数据信息
}
source increment : mysql
{
sql_query_pre = SET NAMES utf8
sql_query = SELECT p.pid,p.tid,p.fid,p.dateline,p.authorid, p.subject,p.message,t.digest,t.displayorder,t.lastpost,t.special FROM pre_forum_post AS p LEFT JOIN pre_forum_thread AS t USING(tid) WHERE pid >(SELECT maxid FROM pre_coreseek WHERE id=1)
}
#index定义
index mysql
{
source = mysql #对应的source名称
path = /home/data/mysql #请修改为实际使用的绝对路径,例如:/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 increment : mysql
{
source=increment
path = /home/data/increment
}
#全局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 = /tmp/searchd_mysql.pid #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
log = /tmp/searchd_mysql.log #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
query_log = /tmp/query_mysql.log #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
}
####第一次启动建立全索引
/usr/local/coreseek/bin/indexer -c /etc/mysql.conf --all
###启动searchd 后台模式,启动前一定先建立好全索引,不然启动失败或增量索引部分会索引不到
/usr/local/coreseek/bin/searchd -c /etc/mysql.conf ###启动
/usr/local/coreseek/bin/searchd -c /etc/mysql.conf --stop ###停止
####增量索引
/usr/local/coreseek/bin/indexer -c /etc/mysql.conf increment --rotate
#####合并索引比重建全索引快速,定期执行合并索引
/usr/local/coreseek/bin/indexer -c etc/mysql.conf --merge mysql increment --merge-dst-range deleted 0 0 --rotate
可以写个定时cron每隔30分钟作一次增量索引
可以写个定时cron每隔1天作一次全索引以确定保持数据的一致性