coreseek在windows下的配置、运行与实时更新(sphinx)

官方文档有很多疏漏,故此多方尝试,将正确的贴出来:

1、bin/csft_mysql.conf:

#源定义
source mysql
{
type = mysql

sql_host = localhost
sql_user = root
sql_pass = merry05
sql_db = test
sql_port = 3306
sql_query_pre = SET NAMES utf8
sql_query = SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title,content FROM documents
#sql_query第一列id需为整数
#title、content作为字符串/文本字段,被全文索引
sql_attr_uint = group_id #从SQL读取到的值必须为整数
sql_attr_timestamp = date_added #从SQL读取到的值必须为整数,作为时间属性

sql_query_info = SELECT * FROM documents WHERE id=$id #命令行查询时,从数据库读取原始数据信息
sql_query_post_index = REPLACE INTO counter (uid,maxid) VALUES (1,$maxid)
}

#index定义
index mysql
{
source = mysql #对应的source名称
path = var/data/mysql
docinfo = extern
mlock = 0
morphology = none
min_word_len = 1
html_strip = 0
charset_dictpath = etc/ #Windows环境下设置,/符号结尾
charset_type = zh_cn.utf-8
#charset_table=……
ngram_len=0
}

source delta:mysql
{
sql_query_pre = SET NAMES utf8
sql_query = SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title,content FROM documents WHERE id>(SELECT maxid FROM counter WHERE uid=1)
}
#增量索引
index delta:mysql
{
source = delta #对应的source名称
path = var/data/mysql_delta #这里的path要与mysql不一样,不然会运行时错误,进程强制退出
}

#全局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 = var/log/searchd_mysql.pid
log = var/log/searchd_mysql.log
query_log = var/log/query_mysql.log
}

注解:mysql为主索引,delta为增量索引

2、进行索引

bin/indexer -–config etccsft_mysql.conf mysql

3、启动searchd进程

bin/searchd --config etccsft_mysql.conf –-pidfile

注解:–pidfile这个选项一定要添加,强制生成pid,不然在合并索引时会报pid文件无法打开错误(这项非常重要)

4、生成增量索引

bin/indexer –-config etccsft_mysql.conf delta -–rotate

5、主索引和增量索引合并

bin/indexer –-config etccsft_mysql.conf -–merge mysql delta -–rotate

在searchd进程运行时–-rotate选项一定要添加,详见文档

如果要在合并,将某些文档移出索引时,需要:

bin/indexer –-config etccsft_mysql.conf -–merge mysql delta -–rotate -–merge-dst-range group_id 2 2

注解:-–merge-dst-range是合并生成主索引的范围开关;这句的意思是只有主索引的group_id属性为2,并且子索引的group_id属性为2,才能被合并生成;否则会被过滤掉,移出主索引。
过滤器可以多个,并且全部满足时才能在最终合并的索引出现

 

你可能感兴趣的:(sphinx,coreseek,中文检索引擎)