sphinx配置文件

这类配置文件本来也没必要分享,但想想或许别人能参考一二。
/opt/modules/sphinx/bin/indexer –all –rotate >> indexlog #全量重建索引
/opt/modules/sphinx/bin/indexer delta –rotate >> deltaindexlog #增量索引
shell

#!/bin/sh
cd /www/s.404xs.cn/shell/
ps -ef|grep 404xs_sync|grep -v grep|awk '{print $2}'|xargs -t -i kill -9 {}
nohup /opt/modules/php/bin/php 404xs_sync.php >> xs8_sync_log &

配置


source mysql
{
  type                    = mysql
    sql_host                = localhost
    sql_user                = root
    sql_pass                = 
    sql_db                  = so_book
    sql_port                = 3306 # optional, default is 3306
    sql_query_pre           = SET NAMES utf8
    sql_query_pre 			= REPLACE INTO sph_counter SELECT 1, MAX(updated) FROM so_book
    sql_query_range			= SELECT MIN(id),MAX(id) FROM so_book
    sql_range_step 			= 1024
     #换行以 \ 结尾  SQL复杂是为了确保作品有多个作品名也被搜索到
    sql_query               = SELECT b.id as id, n.id as nid, b.sid as sid, b.bid, n.title, b.author, b.hero, b.plot,b.cate, b.bytes as bytes, b.bookread as bookread, b.pubtime as pubtime, b.bookstatus,b.series,b.signbook, b.hits, b.favs, b.texts, b.vote, b.regime, b.site,b.style, b.epochs, b.status, b.vipbook FROM so_book as b left join so_bookname as n on b.id = n.pid where b.updated<=( SELECT max_doc_id FROM sph_counter WHERE counter_id=1 ) and b.id>=$start AND b.id<=$end
    sql_attr_uint           = nid           #从SQL读取到的值必须为整数
    sql_attr_uint 			= bid
    sql_attr_uint 			= site
    sql_attr_uint       	= pubtime #从SQL读取到的值必须为整数,作为时间属性


    sql_query_info          = SELECT * FROM so_book WHERE id=$id #命令行查询时,从数据库读取原始数据信息

}

index mysql
{
  source                  = mysql
    path                    = /opt/modules/sphinx/var/data/mysql
    docinfo                 = extern
    mlock                   = 0
    morphology              = none
    min_word_len            = 1
    charset_type            = utf-8
    charset_table           = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F
    ngram_chars             = U+3000..U+2FA1F
    html_strip              = 0
}

#增量源定义 delta_src 中的sql_query_pre的个数需和mysql 对应,否则可能搜索不出相应结果 
source delta: mysql
{
  sql_ranged_throttle		= 100
    sql_query_pre			= SET NAMES utf8
    sql_query_pre			=
    sql_query_range			= SELECT MIN(id),MAX(id) FROM so_book
    sql_range_step 			= 1024
    sql_query    			= SELECT b.id as id, n.id as nid, b.sid as sid, b.bid, n.title, b.author, b.hero, b.plot, b.cate, b.bytes as bytes, b.bookread as bookread, b.pubtime as pubtime, b.bookstatus, b.series, b.signbook, b.hits, b.favs, b.texts, b.vote, b.regime, b.site, b.style, b.epochs, b.status, b.vipbook FROM so_book as b left join so_bookname as n on b.id = n.pid where b.updated >( SELECT max_doc_id FROM sph_counter WHERE counter_id=1 ) and b.id>=$start AND b.id<=$end
}

#delta定义 delta可全部复制主索引,然后更改source 和path如下
index delta: mysql   #增量索引
{
  source                  = delta
    path                    = /opt/modules/sphinx/var/data/delta
}


indexer
{
  mem_limit				= 32M
}


searchd
{
#port					= 9312
  listen					= 0.0.0.0:9312
    log						= /opt/modules/sphinx/var/log/searchd.log
    query_log 				= /opt/modules/sphinx/var/log/query.log
    read_timeout        	= 5
    max_children        	= 30
    pid_file         		= /opt/modules/sphinx/var/log/searchd.pid
    max_matches           	= 10000
    seamless_rotate     	= 1
    preopen_indexes      	= 0
    unlink_old            	= 1
}

Comment (1)

  1. Pingback: 浅谈搜索httpcws+sphinx | HHT原创小站

Leave a Comment

电子邮件地址不会被公开。 必填项已用*标注