linux下coreseek 安裝及使用方法詳解

來源:互聯網
上載者:User

一般網站都需要搜尋功能,如果是php+mysql網站,建議選擇coreseek,如果是java網站建議使用lucene,coreseek 是一款很好的中文全文檢索索引/搜尋軟體,支援高速建立索引、有很強的擴充性、支援分布式檢索,支援不同的搜尋模式(’完全符合’,’短語匹配’,’任一匹配’)。

一、coreseek 安裝

1:安裝mmseg分詞庫

wget http://www.coreseek.cn/uploads/csft/4.0/coreseek-3.2.14-beta.tar.gz
tar -zxvf coreseek-3.2.14-beta.tar.gz
cd coreseek-3.2.14-beta
cd mmseg-3.2.14
./bootstrap   
./configure --prefix=/usr/local/mmseg3 #配置安裝目錄
make
make install
cd ..

2:安裝coreseek

cd csft-3.2.14
sh buildconf.sh
./configure --prefix=/usr/local/coreseek  --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/mmseg3/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg3/lib/ --with-mysql=/usr/local/mysql
make
make install
cd..

3:測試mmseg分詞和coreseek檢索

cd /usr/local/src/coreseek-3.2.14
cd testpack
cat var/test/test.xml    #現實的是中文的內容
/usr/local/mmseg3/bin/mmseg -d /usr/local/mmseg3/etc var/test/test.xml #顯示xml檔案內容
/usr/local/coreseek/bin/indexer -c etc/csft.conf --all #建立索引
/usr/local/coreseek/bin/search -c etc/csft.conf # 進行搜尋

二、coreseek配置和使用

1:配置example.conf檔案

cd /usr/local/coreseek/etc
cp sphinx-min.conf.dist example.conf

對example.conf的配置進行改造,變成我們所需的設定檔。

source example
{
    type                    = mysql
    sql_host                = localhost
    sql_user                = ***
    sql_pass                = ***
    sql_db                    = ***
    sql_port                = 3306
    sql_sock            = /tmp/mysql.sock   
    sql_query_pre            = SET NAMES utf8
    sql_query                = SELECT id,content FROM table_name #不管表的主鍵叫什麼,查出來的結果都是為id
   sql_query_info_pre      = SET NAMES utf8                      #命令列查詢時,設定正確的字元集
   sql_query_info          = SELECT * FROM table WHERE id=$id  LIMIT 100#命令列查詢時,從資料庫讀取未經處理資料資訊
}

#index定義

index example
{
    source            = example             #對應的source名稱
   path            = /usr/local/coreseek/var/data/example/ #請修改為實際使用的絕對路徑
   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環境下設定,/符號結尾,最好給出絕對路徑,
   charset_type        = zh_cn.utf-8
}


#全域index定義

indexer
{
    mem_limit            = 128M
}

#searchd服務定義

searchd
{
    listen                  =   9312
    read_timeout        = 5
    max_children        = 60
    max_matches            = 1000
    seamless_rotate        = 0
    preopen_indexes        = 0
    unlink_old            = 1
    pid_file = /usr/local/coreseek/var/log/searchd_example.pid  #請修改為實際使用的絕對路徑,例如:/usr/local/coreseek/var/...
   log = /usr/local/coreseek/var/log/searchd_example.log  #請修改為實際使用的絕對路徑,例如:/usr/local/coreseek/var/...
   query_log = /usr/local/coreseek/var/log/query_example.log #請修改為實際使用的絕對路徑,例如:/usr/local/coreseek/var/...
}

2:開啟searchd服務 (這點很重要)

coreseek剛安裝後searchd服務是沒開啟的,需要先開啟,不然建立索引的時候會出錯。

先在 /usr/local/src/coreseek/var/log下建立一個searchd_example.pid檔案,然後執行下面的代碼:

/usr/local/coreseek/bin/searchd --config /usr/local/coreseek/etc/example.conf

3:建立索引

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

出現下面的提示:

 

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 '/usr/local/coreseek/etc/example.conf'...
indexing index 'example'...
collected 1 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 1 docs, 631 bytes
total 0.005 sec, 118854 bytes/sec, 188.35 docs/sec
total 1 reads, 0.000 sec, 0.8 kb/call avg, 0.0 msec/call avg
total 5 writes, 0.000 sec, 0.5 kb/call avg, 0.0 msec/call avg
rotating indices: succesfully sent SIGHUP to searchd (pid=14094).
說明coreseek已經可以使用了。
可以把建立索引的命令寫入crontab裡面進行定時,即時更新索引。

4:php 和 coreseek 結合進行查詢

先下載sphinxapi,然後檔案引入結合php進行查詢,下面更多參數的詳解和配置,可以參考 coreseek api php手冊

require_once('sphinxapi');
$s = new SphinxClient();
$s->SetServer('127.0.0.1','9312'); //設定searchd的主機名稱和TCP連接埠
$s->SetConnectTimeout(1); // 設定連線逾時
$s->SetMatchMode(SPH_MATCH_BOOLEAN); //設定全文檢索查詢的匹配模式
$page_size=20;//自己定義的頁數
$s->SetLimits($start,$page_size); //設定返回結果集位移量和數目
$s->SetSortMode( SPH_SORT_EXTENDED,"good_count DESC, @id DESC" ); // 設定排序
$s->SetArrayResult(true);//控制搜尋結果集的返回格式
$res = $s->Query($keyword,'*');// 執行搜尋查詢
$res_list = $res['matches'];

coreseek安裝遇到的錯誤和問題解決方案

1、測試mmseg分詞的時候

執行


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


提示下面的錯誤:


/usr/local/coreseek/bin/indexer: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory


原因:sphinx indexer的依賴庫ibmysqlclient.so.18找不到。

解決辦法:
vi /etc/ld.so.conf
加入 /usr/local/mysql/lib
然後運行 ldconfig
問題解決

2、執行索引的時候


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


提示下面的錯誤:


FATAL: failed to open /usr/local/coreseek/var/data/ttd_article/.tmp.spl: No such file or directory, will not index. Try --rotate option.
原因:source源找不到mysql.sock

解決辦法:在設定檔csft_ttd_search.conf(自己建立的檔案)的 source源 加入下面的代碼

sql_sock   = /tmp/mysql.sock

3、執行索引的時候,出現的警告,導致索引沒建立成功

WARNING: failed to open pid_file '/usr/local/coreseek/var/log/searchd_ttd_search.pid'.
WARNING: indices NOT rotated.
原因:找不到searchd_ttd_search.pid檔案

解決辦法:在’/usr/local/coreseek/var/log 下建立searchd_ttd_search.pid檔案

再執行/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_ttd_search.conf –all –rotate
出現了另外一個警告:


WARNING: failed to scanf pid from pid_file '/usr/local/coreseek/var/log/searchd_ttd_search.pid'.
WARNING: indices NOT rotated.

原因:雖然建立了searchd_ttd_search.pid檔案,但是裡面沒有寫入進程id

解決辦法(根本原因):在執行索引之前沒有啟動searchd服務,因此執行下面的命令


/usr/local/coreseek/bin/searchd --config /usr/local/coreseek/etc/ttd_search.conf

出現了期待已久的成功提示:


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 '/usr/local/coreseek/etc/ttd_search.conf'...
listening on all interfaces, port=9312
rotating index 'mysql': success

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.