天天看點

Ubuntu + coreseek + python + mysql (二、配置資料源和索引)

接上篇

安裝好coreseek後,現在開始配置資料源和索引

在終端輸入cd ~回退到根目錄

然後  cd  /usr/local/coreseek/etc/csft.conf  進入配置檔案(如果沒有csft.conf,那就建立一個空文檔,命名為csft.conf)在這個檔案裡,怎麼配置呢,看我都已經寫好了

其中,sql_user、   sql_pass、   sql_db、   sql_port、   sql_query 要根據自己的情況設定。

檔案裡的路徑,要使用絕對路徑,Ubuntu系統就是/usr/local/coreseek/....

#MySQL資料源配置,詳情請檢視:http://www.coreseek.cn/products-install/mysql/
#請先将var/test/documents.sql導入資料庫,并配置好以下的MySQL使用者密碼資料庫

#源定義
source mysql   #source名稱
{
    type                    = mysql

    sql_host                = localhost
    sql_user                = root
    sql_pass                = admin
    sql_db                  = test
    sql_port                = 3306
    sql_query_pre           = SET NAMES utf8

    sql_query               = SELECT id, name, text FROM tb_test
                                           #sql_query第一列id需為整數
                                           #title、content作為字元串/文本字段,被全文索引
    sql_attr_uint           = id           #從SQL讀取到的值必須為整數
    #sql_attr_timestamp     = date_added #從SQL讀取到的值必須為整數,作為時間屬性

    sql_query_info_pre      = SET NAMES utf8                                        #指令行查詢時,設定正确的字元集
    sql_query_info          = SELECT * FROM tb_test WHERE id = $id  #指令行查詢時,從資料庫讀取原始資料資訊
}

#index定義
index mysql  #index名稱,要和source的名稱相同嘛,此處兩者都為mysql
{
    source          = mysql             #對應的source名稱
    path            = /usr/local/coreseek/var/data/mysql #請修改為實際使用的絕對路徑,例如:/usr/local/coreseek/var/...
    docinfo         = extern
    mlock           = 0
    morphology      = none
    min_word_len    = 1
    html_strip      = 0

    #中文分詞配置,詳情請檢視:http://www.coreseek.cn/products-install/coreseek_mmseg/
    charset_dictpath   = /usr/local/mmseg3/etc/ #BSD、Linux環境下設定,/符号結尾
    #charset_dictpath  = etc/                             #Windows環境下設定,/符号結尾,最好給出絕對路徑,例如:C:/usr/local/coreseek/etc/...
    charset_type       = zh_cn.utf-8
}

#全局index定義
indexer
{
    mem_limit          = 128M
}

#searchd服務定義
searchd
{
    listen             =   9312
    read_timeout       = 5
    max_children       = 30
    max_matches        = 1000
    seamless_rotate    = 0
    preopen_indexes    = 0
    unlink_old         = 1
    pid_file = /usr/local/coreseek/var/log/searchd_mysql.pid  #請修改為實際使用的絕對路徑,例如:/usr/local/coreseek/var/...
    log = /usr/local/coreseek/var/log/searchd_mysql.log        #請修改為實際使用的絕對路徑,例如:/usr/local/coreseek/var/...
    query_log = /usr/local/coreseek/var/log/query_mysql.log #請修改為實際使用的絕對路徑,例如:/usr/local/coreseek/var/...
    binlog_path =                                #關閉binlog日志
}      

配置好後,用終端進入coreseek目錄,運作indexer和searchd,生成索引

然後就可以運作search來通過終端進行搜尋了!

1. cd /usr/local/coreseek/ 進入coreseek目錄

2. ./bin/indexer --all   來生成全部索引(或者./bin/indexer mysql  來生成名稱為mysql的索引 )

(補充:如果寫成 ./bin/indexer mysql --rotate 則表示重新生成名為mysql的索引,寫成./bin/indexer --all --rotate表示重新生成全部索引)

Ubuntu + coreseek + python + mysql (二、配置資料源和索引)

3. 生成索引後,如果沒有Fatal 或 erroe(warning可以不做處理),然後./bin/searchd

Ubuntu + coreseek + python + mysql (二、配置資料源和索引)