Sphinx主索引和增量索引來實現索引實時更新的關鍵步驟

1.配置csft.conf文件 

vim /etc/csft.confmysql

#
# Minimal Sphinx configuration sample (clean, simple, functional)
#

source test_t0
{
    type                    = mysql

    sql_host                = localhost
    sql_user                = root
    sql_pass                = 123123
    sql_db                    = test
    sql_port                = 3306    # optional, default is 3306
        sql_query_pre                           = SET NAMES utf8
    sql_query_pre                           = REPLACE INTO count_t0 select 1,max(id) from t0
    sql_query                = \
        SELECT id, description, name, age \
        FROM t0 WHERE id <= (SELECT max_id FROM count_t0 where c_id=1 )

    sql_attr_uint            = age
        #sql_attr_timestamp        = date_added

        #sql_query_info            = SELECT * FROM documents WHERE id=$id
}

source test_t0_delta:test_t0
{
    sql_query_pre        = SET NAMES utf8
    sql_query_pre        =
    sql_query                = \
        SELECT id, description, name, age \
        FROM t0 WHERE id > (SELECT max_id FROM count_t0 where c_id=1 )
}

index test_t0
{
    source                    = test_t0
    path                    = /usr/local/coreseek/var/data/test_t0
    docinfo                    = extern
        charset_dictpath                        = /usr/local/mmseg/etc/
    charset_type                    = zh_cn.utf-8
}

index test_t0_delta:test_t0
{
    source                    = test_t0_delta
    path                    = /usr/local/coreseek/var/data/test_t0_delta
    docinfo                    = extern
        charset_dictpath                        = /usr/local/mmseg/etc/
    charset_type                    = zh_cn.utf-8
}

indexer
{
    mem_limit                = 512M
}


searchd
{
    port                    = 9312
    log                        = /usr/local/coreseek/var/log/searchd.log
    query_log                = /usr/local/coreseek/var/log/query.log
    read_timeout            = 5
    max_children            = 30
    pid_file                = /usr/local/coreseek/var/log/searchd.pid
    max_matches                = 1000
    seamless_rotate            = 1
    preopen_indexes            = 0
    unlink_old                = 1
}

 2.從新生成主索引的shell腳本文件

cd /usr/local/shellsql

vim test_t0.shshell

#!/bin/sh
/usr/local/coreseek/bin/searchd -c /etc/csft.conf --stop #中止searchd
/usr/local/coreseek/bin/indexer -c /etc/csft.conf test_t0 #生成索引
/usr/local/coreseek/bin/searchd -c /etc/csft.conf #啓動searchd

chmod 755 test_t0.shvim

3.從新生成增量索引的shell腳本文件

cd /usr/local/shellless

vim test_t0_delta.shui

#!/bin/sh
/usr/local/coreseek/bin/searchd -c /etc/csft.conf --stop
/usr/local/coreseek/bin/indexer -c /etc/csft.conf test_t0_delta

/usr/local/coreseek/bin/searchd -c /etc/csft.conf #啓動searchd

chmod 755 test_t0_delta.shspa

4.添加到定時任務

crontab -ecode

30 3 * * * /usr/local/shell/test_t0.sh #天天凌晨3點半更新主索引
*/10 * * * * /usr/local/shell/test_t0_delta.sh #每隔10分鐘更新增量索引
相關文章
相關標籤/搜索