sphinx 添加增量索引小结

2015.12.28 No Comments

coreseek/sphinx 实时索引
1. 建表 用来做主索引和增量索引的区分点
create table ph_counter(
counter_id int auto increment primary key,
max_doc_id int
)ENGINES=MYISAM  DEFAULT CHARSET=utf8;

2.vim  csvf.conf
#添加
sql_query_pre          = replace into sph_counter select 1,max(id)     FROM details

将sql_query       =SELECT id, createdby, body          FROM details
修改为sql_query       =SELECT id,createdby, body          FROM details where id<=(select max_doc_id from ph_counter where counter_id=1)

3. 添加增量数据源
source delta : main
{
sql_query_pre =set names utf8
sql_query=SELECT id,createdby, body from details where id>(select ma    x_doc_id from sph_counter where counter_id=1)
#sql_ranged_throttle    = 100
}

4. 添加增量数据索引
index delta :  main
{
source=delta
//增量数据源地址
path                    = /data/server/coreseek/var/data/delta
#morphology             = stem_en
}

5. ./indexer delta --rotate 生成增量索引
计数器表sph_counter 值只有在执行主数据源./indexer main --rotate的时候才会更新

 

6.添加sh文件

main.sh

#!/bin/bash
#main.sh
/data/coreseek/bin/indexer main --rotate >>/data/shellcode/sphinx/log/main.log

delta.sh

#!/bin/bash
#main.sh
/data/coreseek/bin/indexer main --rotate >>/data/shellcode/sphinx/log/delta.log
7. 添加定时任务
crontab -e
#每天3点,生成详情表sphinx主数据索引
00 03 * * *  /data/shellcode/sphinx/main.sh
#每五分钟,生成详情表增量数据索引
*/5 * * * *  /data/shellcode/sphinx/delta.sh

 

 

 

Related Posts:

发表评论