sphinx搜索集群搭建示例(多产品)

时间:2021-11-03 01:19:27

每个产品项目分配一个搜索配置,每个配置分不同的数据库或端口区分不同的产品,每个配置启动一个守户进程


配置文件project1_csft.conf示例:

#Test source
source test_main
{
    type            = mysql
    sql_host        = 192.168.1.100
    sql_user        = root
    sql_pass        = 123456
    sql_db          =  test
    sql_port        = 3306
    sql_query_pre   = SET NAMES utf8
    sql_query_pre   = replace into index_delta select 2,'test',UNIX_TIMESTAMP() from test

    sql_query       = SELECT SQL_NO_CACHE id, ctime,2 as type,title,alias_name FROM test where status=1 and mtime <= ( s
elect max_mtime from index_delta where type='user' )
    sql_attr_uint   = type
    sql_attr_timestamp      = ctime
}

index test_main_idx
{
    source           = test_main
    path             = /usr/local/coreseek/var/project1/test
    docinfo          = extern
    mlock            = 0
    morphology       = none
    min_word_len     = 1
    html_strip       = 0

    charset_dictpath = /usr/local/mmseg/etc/
    stopwords        =   /usr/local/mmseg/etc/stopwords.txt
    charset_type     = zh_cn.utf-8
    charset_table    =
    ngram_len        = 0
}

#Test delta index source
source test_delta : test_main
{
    sql_query_pre           = SET NAMES utf8
    sql_query               = SELECT SQL_NO_CACHE id as id,ctime,2 as type,title,alias_name FROM test where mtime > ( select m
ax_mtime from index_delta where type='user' )
    sql_attr_uint   = type
    sql_attr_timestamp      = ctime

}


#Test delta index
index test_delta_idx : test_main_idx
{
    source            = test_delta
    path            = /usr/local/coreseek/var/project1/test_delta
}


全索引生成:

/usr/local/coreseek/bin/indexer -c  /usr/local/coreseek/etc/project1_csft.conf  --all


sphinx启动:

/usr/local/coreseek/bin/searchd --config /usr/local/coreseek/etc/project1_csft.conf --pidfile

sphinx停止:
/usr/local/coreseek/bin/searchd --config /usr/local/coreseek/etc/project1_csft.conf --stop

根据不同业务创建不同的产品索引配置文件并启动


前端用封装的Sphinxapi.php调用不同服务器上不同产品索引文件即可