天天看點

coreseek安裝及使用 coreseek實戰(一):windows下coreseek的安裝與測試

coreseek實戰(一):windows下coreseek的安裝與測試

12月02, 2013 by SJY

網上關于 coreseek 在 windows 下安裝與使用的教程有很多,官方也有詳細的教程,這裡我也隻是按着官方提供的教程詳細的動手操作一遍,加深印象。官方頁面見:http://www.coreseek.cn/products-install/install_on_windows/

第一步:下載下傳coreseek 3.2.14 for windows,并安裝

1、下載下傳後解壓得到源程式目錄 coreseek-3.2.14-win32 ,檔案夾重命名一下,簡單一些,命名為 coreseek;

2、将 coreseek 檔案夾移動到 d:\www\ 下(根據你個人愛好,放哪都可以);

3、“開始”——>“運作”——>輸入cmd,打開指令行視窗——>執行 "d: 回車"——>執行 "cd www\coreseek\",進入到 coreseek目錄下;

4、執行 "set PATH=%CD%\bin;%PATH%"。設定path,目的是為了能夠調用bin目錄下的 cat.exe、iconv.exe 等;

5、将 searchd 安裝成為一個服務。執行 "bin\searchd --install --config d:/www/coreseek/etc/csft_mysql.conf",安裝成功後指令行視窗會提示" services searchd installed successfully"。注意兩點:

(1)、win7下指令行視窗需要以管理者身份運作,否則會出現”fatal openscmanager“錯誤而無法安裝

(2)、如果不把 searchd 安裝成為服務,那每次使用 coreseek 全文搜尋,都得在指令行視窗打開 searchd 服務且不可關閉或停止(指令行視窗不需要開啟,使用api接口時需要)

-----第5點2013.2.7号修正,以上為錯誤的------

首先,需要配置好 index索引後,才可以安裝成為一個服務,是以,這點放在這是錯誤的;

其次,是補充一點,無法正常安裝,或安裝後啟動該服務時出現1067錯誤,很有可能是路徑問題:一是需要注意資料源配置檔案裡全部使用絕對路徑;二是上面的 install指令,也需要使用絕對路徑,而且路徑用 '/' ,不能是 '\'。

第二步:mysql資料源的配置與建立索引檔案

1、配置 mysql 資料源及測試(在 coreseek\etc\csft_mysql.conf 檔案)

說明:這裡我沒有使用 coreseek 自帶的document.sql,而是使用了 我自己本身已有的一個資料庫資料,關于 csft_mysql.conf 配置檔案中的各個配置項,我們在後面的文章中會做測試與學習,具體參考官方 coreseek 3.2 / sphinx 0.9.9 中文手冊。

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

#源定義
source weibo
{
    type               = mysql
    sql_host           = localhost
    sql_user           = root
    sql_pass           = 123456
    sql_db             = weibo
    sql_port           = 3306
    sql_query_pre      = SET NAMES utf8

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

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

#index定義
index weibo
{
    source            = weibo             #對應的source名稱
    path            = 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    = d:/www/coreseek/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 = var/log/searchd_mysql.pid  #請修改為實際使用的絕對路徑,例如:/usr/local/coreseek/var/...
    log = var/log/searchd_mysql.log        #請修改為實際使用的絕對路徑,例如:/usr/local/coreseek/var/...
    query_log = var/log/query_mysql.log #請修改為實際使用的絕對路徑,例如:/usr/local/coreseek/var/...
}      

2、建立索引

在指令行視窗下執行 " bin\indexer -c etc\csft_mysql.conf weibo",即:建立名為weibo的資料源的索引。如果需要建立 csft_mysql.conf 配置檔案中的所有索引,剛使用 --all 替代 weibo。

D:\www\coreseek>bin\indexer -c etc\csft_mysql.conf weibo
Coreseek Fulltext 3.2 [ Sphinx 0.9.9-release (r2117)]
Copyright (c) 2007-2011,
Beijing Choice Software Technologies Inc (http://www.coreseek

 using config file 'etc\csft_mysql.conf'...
indexing index 'weibo'...
collected 8 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 8 docs, 1381 bytes
total 0.188 sec, 7319 bytes/sec, 42.40 docs/sec
total 2 reads, 0.000 sec, 1.2 kb/call avg, 0.0 msec/call avg
total 7 writes, 0.000 sec, 0.9 kb/call avg, 0.1 msec/call avg      

此時,在 coreseek\var\data 下發現,生成6個檔案。

第三步:資料測試(指令行下不需要開啟 searchd 服務)

1、測試搜尋中文。指令 為“ echo 搜尋的詞 | iconv -f gbk -t utf-8 | search -c etc\csft_mysql.conf --stdin | iconv -f utf-8 -t gbk ”

D:\www\coreseek>echo 生意 | iconv -f gbk -t utf-8 | search -c etc\csft_mysql.con
f --stdin | iconv -f utf-8 -t gbk
Coreseek Fulltext 3.2 [ Sphinx 0.9.9-release (r2117)]
Copyright (c) 2007-2011,
Beijing Choice Software Technologies Inc (http://www.coreseek.com)

 using config file 'etc\csft_mysql.conf'...
index 'weibo': query '生意
': returned 1 matches of 1 total in 0.013 sec

displaying matches:
1. document=2, weight=1, hit=22, dates=Thu Jan 01 08:33:32 1970
        id=2
        title=隊照排貨照炒 百度生意照做
        content=他還告訴記者,如果顧客在他們店購買iPhone5,iPhone4S的回收價格可
以再往上浮動300元左右,記者随後咨詢了另外幾家手機店,發現回收價格基本在1500元至2
000元之間
        hit=22
        dates=2012-10-01

words:
1. '生意': 1 documents, 1 hits      

2、搜尋英文,出現亂碼是正常的。指令為” bin\search -c etc\csft_mysql.conf 搜尋詞“

D:\www\coreseek>bin\search -c etc\csft_mysql.conf emall
Coreseek Fulltext 3.2 [ Sphinx 0.9.9-release (r2117)]
Copyright (c) 2007-2011,
Beijing Choice Software Technologies Inc (http://www.coreseek.com)

 using config file 'etc\csft_mysql.conf'...
index 'weibo': query 'emall ': returned 2 matches of 2 total in 0.013 sec

displaying matches:
1. document=8, weight=2, hit=0, dates=Thu Jan 01 08:33:32 1970
        id=8
        title=emall鐢靛瓙鍟嗗煄
        content=绁濊春emall鍟嗗煄鎴愮珛
        hit=0
        dates=2012-12-01
2. document=9, weight=2, hit=0, dates=Thu Jan 01 08:33:32 1970
        id=9
        title=emall鐢靛瓙鍟嗗煄
        content=绁濊春emall鍟嗗煄鎴愮珛
        hit=0
        dates=2012-12-01

words:
1. 'emall': 2 documents, 4 hits      

補充說明(重點):測試中可能會出現以下兩個問題。

1、搜尋中文時,出現 iconv 不是内部或外部指令。解決辦法:運作一下 "set PATH=%CD%\bin;%PATH%",即可解決;

2、搜尋中文時,很多明明是詞語,但卻被拆分成單個字。解決辦法:需要使用同義詞\複合詞才能搞定,見官方教程mmseg 同義詞/複合分詞處理。

原文 http://www.cnblogs.com/phpway/archive/2013/02/06/2908097.html

歡迎轉載,但請保留原文位址 http://www.sjyhome.com/linux/coreseek-practice-1.html

繼續閱讀