wordpress coreseek全文搜索配置

原创
2012/10/03 22:39
阅读数 3.6K
#
# Minimal Sphinx configuration sample (clean, simple, functional)
#
source wp_posts
{
	# data source type. mandatory, no default value
	# known types are mysql, pgsql, mssql, xmlpipe, xmlpipe2, odbc
	type			= mysql
	#####################################################################
	## SQL settings (for 'mysql' and 'pgsql' types)
	#####################################################################

	# some straightforward parameters for SQL source types
	sql_host		= localhost
	sql_user		= root
	sql_pass		= root
	sql_db			= test
	sql_port		= 3306	# optional, default is 3306

	#待索引数据获取前查询
    sql_query_pre		= SET NAMES utf8
	sql_query_pre		= SET SESSION query_cache_type=OFF


    sql_query       = select ID,post_content,post_title,post_name,guid,UNIX_TIMESTAMP(post_date) post_date \
                        from wp_posts
                        
	#sql_field_string		= post_title
    #sql_field_string     = post_content
    sql_attr_timestamp = post_date
    #sql_query_info      = select * from wp_posts where ID=$id
}
index wp_posts
{
    source          = wp_posts
	path			= /home/coreseek/data/59n_posts
	docinfo			= extern
    charset_dictpath = /usr/local/mmseg3/etc/
	charset_type		= zh_cn.utf-8
}

########增量索引,进行实时更新

source wp_posts_rt:wp_posts
{
    sql_query       = select ID,post_content,post_title,post_name,guid,UNIX_TIMESTAMP(post_date) \
                        post_date \
                        from wp_posts where UNIX_TIMESTAMP(post_modified) > UNIX_TIMESTAMP() - 300
}
index wp_posts_rt
{
    source          = wp_posts_rt
	path			= /home/coreseek/data/59n_posts_rt
	docinfo			= extern
    charset_dictpath = /usr/local/mmseg3/etc/
	charset_type		= zh_cn.utf-8
}


source wp_comment
{
    type			= mysql
    sql_host		= localhost
	sql_user		= root
	sql_pass		= root
	sql_db			= test
	sql_port		= 3306	# optional, default is 3306
    #待索引数据获取前查询
    sql_query_pre		= SET NAMES utf8
	sql_query_pre		= SET SESSION query_cache_type=OFF


    sql_query       = select comment_ID,comment_post_ID,comment_author,comment_content,UNIX_TIMESTAMP(comment_date) comment_date from wp_comments
                        
    sql_attr_uint       = comment_post_ID
	#sql_field_string		= comment_author
    #sql_field_string     = comment_content

    sql_attr_timestamp = comment_date
    #sql_query_info      = select * from wp_comments where comment_ID=$id
}



index wp_comment
{
    source          = wp_comment
	path			= /home/coreseek/data/59n_comment
	docinfo			= extern
    charset_dictpath = /usr/local/mmseg3/etc/
	charset_type		= zh_cn.utf-8
}

########增量索引,进行实时更新

source wp_comment_rt:wp_comment
{
    sql_query       = select comment_ID,comment_post_ID,comment_author,comment_content,UNIX_TIMESTAMP(comment_date) comment_date from wp_comments \
                        where UNIX_TIMESTAMP(comment_date) > UNIX_TIMESTAMP() - 300
}
index wp_comment_rt
{
    source          = wp_comment_rt
	path			= /home/coreseek/data/59n_comment_rt
	docinfo			= extern
    charset_dictpath = /usr/local/mmseg3/etc/
	charset_type		= zh_cn.utf-8
}

indexer
{
	mem_limit		= 256M
}


searchd
{
	listen			= 9312
	listen			= 9306:mysql41
	log			= /usr/local/coreseek/var/log/searchd.log
	query_log		= /usr/local/coreseek/var/log/query.log
	read_timeout		= 5
	max_children		= 10
	pid_file		= /usr/local/coreseek/var/log/searchd.pid
	max_matches		= 1000
	seamless_rotate		= 1
	preopen_indexes		= 1
	unlink_old		= 1
	workers			= threads # for RT to work
}

进行首次索引 

./bin/indexer --all

使用crontab -e进行增量索引进行实时更新

*/4 * * * * /usr/local/coreseek/bin/indexer --rotate wp_posts_rt wp_comment_rt

*/4 * * * * /usr/local/coreseek/bin/indexer --rotate --merge wp_posts wp_posts_rt

*/4 * * * * /usr/local/coreseek/bin/indexer --rotate --merge wp_comment wp_comment_rt

在PHP中使用sphinx扩展进行搜索.

$sp = new SphinxClient();
        $sp->setMatchMode(SPH_MATCH_ANY);
        $result = $sp->query($name);
        //$err 错误
        $err = $sp->GetLastError();
        echo '<pre>';
        var_dump($result);
        var_dump($err);
        echo '</pre>';

展开阅读全文
打赏
1
25 收藏
分享
加载中
mysql足够了 这样折腾纯粹多余
2012/10/09 17:37
回复
举报
没看懂,这啥东东?
2012/10/08 17:01
回复
举报
更多评论
打赏
2 评论
25 收藏
1
分享
返回顶部
顶部