Sphinx全文索引之phpwind配置实例[gbk版] by cubeking
[ 2013-10-11 20:04:14 | 作者: admin ]
PHPWind搜索sphinx配置实例 [修改部分参数就可直接应用于phpwind程序]
部分解读:
如下全文索引使用的是主索引+增量索引的方式,具体大家结合手册了解相关知识
需要创建一张表 [编码自己定,如下是gbk]
CREATE TABLE IF NOT EXISTS `search_counter` (
`counterid` int(11) NOT NULL DEFAULT '0',
`max_doc_id` int(11) NOT NULL DEFAULT '0',
`min_doc_id` int(10) NOT NULL DEFAULT '0',
PRIMARY KEY (`counterid`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk;
csft.conf配置文件
source tmsgs
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = xxxx
sql_db = phpwind
sql_port = 3307 # optional, default is 3306
sql_sock = /tmp/mysql3307.sock
sql_query_pre = SET NAMES gbk
sql_query_pre = SET SESSION query_cache_type=OFF
sql_query_pre = REPLACE INTO search_counter SELECT 1,MAX(tid),MIN(tid) FROM pw_tmsgs
sql_query_range = SELECT min_doc_id, max_doc_id FROM search_counter WHERE counterid = 1
sql_range_step = 1000
sql_query = SELECT th.tid,th.subject,th.authorid,th.postdate,th.lastpost,th.fid,th.digest,th.hits,th.replies,t.content FROM pw_threads th LEFT JOIN pw_tmsgs t USING(tid) WHERE th.tid > $start AND th.tid <= $end
sql_attr_uint = authorid
sql_attr_uint = hits
sql_attr_uint = replies
sql_attr_uint = fid
sql_attr_timestamp = postdate
sql_attr_timestamp = lastpost
sql_attr_uint = digest
}
source addtmsgs
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = xxxx
sql_db = phpwind
sql_port = 3307 # optional, default is 3306
sql_sock = /tmp/mysql3307.sock
sql_query_pre = SET NAMES gbk
sql_query_pre = SET SESSION query_cache_type=OFF
sql_query_range = SELECT max_doc_id, max_doc_id+100000 FROM search_counter WHERE counterid = 1
sql_range_step = 100000
sql_query = SELECT th.tid,th.subject,th.authorid,th.postdate,th.lastpost,th.fid,th.digest,th.hits,th.replies,t.content FROM pw_threads th LEFT JOIN pw_tmsgs t USING(tid) WHERE th.tid > $start AND th.tid <= $end
sql_attr_uint = authorid
sql_attr_uint = hits
sql_attr_uint = replies
sql_attr_uint = fid
sql_attr_timestamp = postdate
sql_attr_timestamp = lastpost
sql_attr_uint = digest
sql_query_post = REPLACE INTO search_counter SELECT 1,MAX(tid),MIN(tid) FROM pw_tmsgs
#sql_attr_uint = tid
}
source threads
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = xxxxxxx
sql_db = phpwind
sql_port = 3307 # optional, default is 3306
sql_sock = /tmp/mysql3307.sock
sql_query_pre = SET NAMES gbk
sql_query_pre = SET SESSION query_cache_type=OFF
sql_query_pre = REPLACE INTO search_counter SELECT 3,MAX(tid),MIN(tid) FROM pw_threads
sql_query_range = SELECT min_doc_id, max_doc_id FROM search_counter WHERE counterid = 3
sql_range_step = 1000
sql_query = SELECT th.tid,th.subject,th.authorid,th.postdate,th.lastpost,th.fid,th.digest,th.hits,th.replies FROM pw_threads th WHERE th.tid > $start AND th.tid <= $end
sql_attr_uint = authorid
sql_attr_uint = hits
sql_attr_uint = replies
sql_attr_uint = fid
sql_attr_timestamp = postdate
sql_attr_timestamp = lastpost
sql_attr_uint = digest
}
source addthreads
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = xxx
sql_db = phpwind
sql_port = 3307 # optional, default is 3306
sql_sock = /tmp/mysql3307.sock
sql_query_pre = SET NAMES gbk
sql_query_pre = SET SESSION query_cache_type=OFF
sql_query_range = SELECT max_doc_id, max_doc_id+100000 FROM search_counter WHERE counterid = 3
sql_range_step = 100000
sql_query = SELECT th.tid,th.subject,th.authorid,th.postdate,th.lastpost,th.fid,th.digest,th.hits,th.replies FROM pw_threads th WHERE th.tid > $start AND th.tid <= $end
sql_attr_uint = authorid
sql_attr_uint = hits
sql_attr_uint = replies
sql_attr_uint = fid
sql_attr_timestamp = postdate
sql_attr_timestamp = lastpost
sql_attr_uint = digest
sql_query_post = REPLACE INTO search_counter SELECT 3,MAX(tid),MIN(tid) FROM pw_threads
#sql_attr_uint = tid
}
index tmsgsindex
{
source = tmsgs
path = /usr/local/csft/var/data/tmsgs
docinfo = extern
charset_type = zh_cn.gbk
#min_prefix_len = 0
#min_infix_len = 2
#ngram_len = 2
charset_dictpath = /usr/local/csft/
min_prefix_len = 0
min_infix_len = 0
min_word_len = 2
}
index addtmsgsindex
{
source = addtmsgs
path = /usr/local/csft/var/data/addtmsgs
docinfo = extern
charset_type = zh_cn.gbk
#min_infix_len = 2
#ngram_len = 2
charset_dictpath = /usr/local/csft/
min_prefix_len = 0
min_infix_len = 0
min_word_len = 2
}
index threadsindex
{
source = threads
path = /usr/local/csft/var/data/threads
docinfo = extern
charset_type = zh_cn.gbk
#min_prefix_len = 0
#min_infix_len = 2
#ngram_len = 2
charset_dictpath = /usr/local/csft/
min_prefix_len = 0
min_infix_len = 0
min_word_len = 2
}
index addthreadsindex
{
source = addthreads
path = /usr/local/csft/var/data/addthreads
docinfo = extern
charset_type = zh_cn.gbk
#min_infix_len = 2
#ngram_len = 2
charset_dictpath = /usr/local/csft/
min_prefix_len = 0
min_infix_len = 0
min_word_len = 2
}
indexer
{
mem_limit = 128M
}
searchd
{
port = 3312
log = /usr/local/csft/var/log/searchd.log
query_log = /usr/local/csft/var/log/query.log
read_timeout = 5
max_children = 30
pid_file = /usr/local/csft/var/log/searchd.pid
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 0
unlink_old = 1
}
部分解读:
如下全文索引使用的是主索引+增量索引的方式,具体大家结合手册了解相关知识
需要创建一张表 [编码自己定,如下是gbk]
CREATE TABLE IF NOT EXISTS `search_counter` (
`counterid` int(11) NOT NULL DEFAULT '0',
`max_doc_id` int(11) NOT NULL DEFAULT '0',
`min_doc_id` int(10) NOT NULL DEFAULT '0',
PRIMARY KEY (`counterid`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk;
csft.conf配置文件
source tmsgs
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = xxxx
sql_db = phpwind
sql_port = 3307 # optional, default is 3306
sql_sock = /tmp/mysql3307.sock
sql_query_pre = SET NAMES gbk
sql_query_pre = SET SESSION query_cache_type=OFF
sql_query_pre = REPLACE INTO search_counter SELECT 1,MAX(tid),MIN(tid) FROM pw_tmsgs
sql_query_range = SELECT min_doc_id, max_doc_id FROM search_counter WHERE counterid = 1
sql_range_step = 1000
sql_query = SELECT th.tid,th.subject,th.authorid,th.postdate,th.lastpost,th.fid,th.digest,th.hits,th.replies,t.content FROM pw_threads th LEFT JOIN pw_tmsgs t USING(tid) WHERE th.tid > $start AND th.tid <= $end
sql_attr_uint = authorid
sql_attr_uint = hits
sql_attr_uint = replies
sql_attr_uint = fid
sql_attr_timestamp = postdate
sql_attr_timestamp = lastpost
sql_attr_uint = digest
}
source addtmsgs
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = xxxx
sql_db = phpwind
sql_port = 3307 # optional, default is 3306
sql_sock = /tmp/mysql3307.sock
sql_query_pre = SET NAMES gbk
sql_query_pre = SET SESSION query_cache_type=OFF
sql_query_range = SELECT max_doc_id, max_doc_id+100000 FROM search_counter WHERE counterid = 1
sql_range_step = 100000
sql_query = SELECT th.tid,th.subject,th.authorid,th.postdate,th.lastpost,th.fid,th.digest,th.hits,th.replies,t.content FROM pw_threads th LEFT JOIN pw_tmsgs t USING(tid) WHERE th.tid > $start AND th.tid <= $end
sql_attr_uint = authorid
sql_attr_uint = hits
sql_attr_uint = replies
sql_attr_uint = fid
sql_attr_timestamp = postdate
sql_attr_timestamp = lastpost
sql_attr_uint = digest
sql_query_post = REPLACE INTO search_counter SELECT 1,MAX(tid),MIN(tid) FROM pw_tmsgs
#sql_attr_uint = tid
}
source threads
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = xxxxxxx
sql_db = phpwind
sql_port = 3307 # optional, default is 3306
sql_sock = /tmp/mysql3307.sock
sql_query_pre = SET NAMES gbk
sql_query_pre = SET SESSION query_cache_type=OFF
sql_query_pre = REPLACE INTO search_counter SELECT 3,MAX(tid),MIN(tid) FROM pw_threads
sql_query_range = SELECT min_doc_id, max_doc_id FROM search_counter WHERE counterid = 3
sql_range_step = 1000
sql_query = SELECT th.tid,th.subject,th.authorid,th.postdate,th.lastpost,th.fid,th.digest,th.hits,th.replies FROM pw_threads th WHERE th.tid > $start AND th.tid <= $end
sql_attr_uint = authorid
sql_attr_uint = hits
sql_attr_uint = replies
sql_attr_uint = fid
sql_attr_timestamp = postdate
sql_attr_timestamp = lastpost
sql_attr_uint = digest
}
source addthreads
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = xxx
sql_db = phpwind
sql_port = 3307 # optional, default is 3306
sql_sock = /tmp/mysql3307.sock
sql_query_pre = SET NAMES gbk
sql_query_pre = SET SESSION query_cache_type=OFF
sql_query_range = SELECT max_doc_id, max_doc_id+100000 FROM search_counter WHERE counterid = 3
sql_range_step = 100000
sql_query = SELECT th.tid,th.subject,th.authorid,th.postdate,th.lastpost,th.fid,th.digest,th.hits,th.replies FROM pw_threads th WHERE th.tid > $start AND th.tid <= $end
sql_attr_uint = authorid
sql_attr_uint = hits
sql_attr_uint = replies
sql_attr_uint = fid
sql_attr_timestamp = postdate
sql_attr_timestamp = lastpost
sql_attr_uint = digest
sql_query_post = REPLACE INTO search_counter SELECT 3,MAX(tid),MIN(tid) FROM pw_threads
#sql_attr_uint = tid
}
index tmsgsindex
{
source = tmsgs
path = /usr/local/csft/var/data/tmsgs
docinfo = extern
charset_type = zh_cn.gbk
#min_prefix_len = 0
#min_infix_len = 2
#ngram_len = 2
charset_dictpath = /usr/local/csft/
min_prefix_len = 0
min_infix_len = 0
min_word_len = 2
}
index addtmsgsindex
{
source = addtmsgs
path = /usr/local/csft/var/data/addtmsgs
docinfo = extern
charset_type = zh_cn.gbk
#min_infix_len = 2
#ngram_len = 2
charset_dictpath = /usr/local/csft/
min_prefix_len = 0
min_infix_len = 0
min_word_len = 2
}
index threadsindex
{
source = threads
path = /usr/local/csft/var/data/threads
docinfo = extern
charset_type = zh_cn.gbk
#min_prefix_len = 0
#min_infix_len = 2
#ngram_len = 2
charset_dictpath = /usr/local/csft/
min_prefix_len = 0
min_infix_len = 0
min_word_len = 2
}
index addthreadsindex
{
source = addthreads
path = /usr/local/csft/var/data/addthreads
docinfo = extern
charset_type = zh_cn.gbk
#min_infix_len = 2
#ngram_len = 2
charset_dictpath = /usr/local/csft/
min_prefix_len = 0
min_infix_len = 0
min_word_len = 2
}
indexer
{
mem_limit = 128M
}
searchd
{
port = 3312
log = /usr/local/csft/var/log/searchd.log
query_log = /usr/local/csft/var/log/query.log
read_timeout = 5
max_children = 30
pid_file = /usr/local/csft/var/log/searchd.pid
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 0
unlink_old = 1
}
评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=2151
这篇日志没有评论。
此日志不可发表评论。