coreseek 安裝、使用(實時索引+分佈式)

Coreseek 是一款中文全文檢索/搜索軟件,基於Sphinx研發並獨立發佈,專攻中文搜索和信息處理領域,它基本兼容sphinx一些特性,很多方面還是傳承於sphinx。

1、Coreseek安裝
下載:http://www.coreseek.cn/uploads/csft/4.0/coreseek-4.1-beta.tar.gz
$tar -zxvf coreseek-4.1-beta

**前提:需提前安裝操作系統基礎開發庫及mysql依賴庫以支持mysql數據源和xml數據源
##安裝mmseg
$ cd mmseg-3.2.14
$ ./bootstrap #輸出的warning信息可以忽略,如果出現error則需要解決
$ ./configure --prefix=/usr/local/mmseg3
$ make && make install
$ cd ..

$cd csft-4.1
$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
$make && make install


PS:在安裝過程中可能會出現一些常見錯誤:
(1)問題:undefined reference to `libiconv'
解決:$vi csft-4.1/src/Makefile
註釋掉:#LIBS = -ldl -lm -lz -lexpat -L/usr/local/lib -lrt -lpthread
替換爲:LIBS = -lm -lexpat -liconv -L/usr/local/lib

(2)如下錯誤:
undefined reference to `dlclose' (-ldl)
undefined reference to `clock_gettime'(-lrt)
解決:$vi csft-4.1/src/Makefile
修改:LDFLAGS = -lrt -ldl

2、使用
$ cd /usr/local/coreseek/etc
$ cp sphinx.conf.dist sphinx.conf
$ vi sphinx.conf


在示例配置文件中,將試圖對MySQL數據庫test中的 documents 表建立索引;因此在這裏還提供了 example.sql 用於給測試表增加少量數據用於測試:
$ mysql -u test < /usr/local/sphinx/etc/example.sql

運行indexer 爲你的數據創建全文索引:
$ cd /usr/local/coreseek/etc
$ /usr/local/coreseek/bin/indexer --all

你可以使用search(注意,是search而不是searchd)實用程序從命令行對索引進行檢索:
$ cd /usr/local/coreseek/etc
$ /usr/local/coreseek/bin/search test

如果要從PHP腳本檢索索引,你需要:

運行守護進程searchd,PHP腳本需要連接到searchd上進行檢索:
$ cd /usr/local/coreseek/etc
$ /usr/local/coreseek/bin/searchd

運行PHP API 附帶的test 腳本(運行之前請確認searchd守護進程已啓動):
$ cd coreseek-4.1-beta/csft-4.1/api
$ php test.php test

將API文件(位於api/sphinxapi.php) 包含進你自己的腳本,開始編程.

PS:(1)索引重新生成,需要重啓searchd或者建索引時使用--rotate;
(2)目前支持數據源類型只能是UTF-8,MySQL4.1起可以通過SET NAMES UTF8設定輸出字符 集爲UTF-8,即使原始數據爲GBK也可(Latin1不能直接使用,需先轉換爲UTF-8或者GBK字符 集);

3、中文分詞核心配置
$vi sphinx.conf
index test1
{
.......
#加入以下設置
charset_dictpath = /usr/local/mmseg3/etc/
charset_type = zh_cn.utf-8
#charset_table = .................... #需將原有註釋掉
ngram_len = 0
}


4、分佈式
加入如下配置:

index dist1
{
type = distributed
local = test1
agent = 172.xx.xx.xx:3312:test1//另一臺機器上安裝的sphinx
agent_connect_timeout = 1000
agent_query_timeout = 3000
}


5、實時索引
添加統計表:
# in MySQL
CREATE TABLE sph_counter
(
counter_id INTEGER PRIMARY KEY NOT NULL,
max_doc_id INTEGER NOT NULL
);

添加增量索引:
$vi sphinx.conf
#修改test1索引數據源
source test1
{
# ...
sql_query_pre = SET NAMES utf8
sql_query_pre = REPLACE INTO sph_counter SELECT 1, MAX(id) FROM documents
sql_query = SELECT id, title, body FROM documents \
WHERE id<=( SELECT max_doc_id FROM sph_counter WHERE counter_id=1 )
}
source delta : test1
{
sql_query_pre = SET NAMES utf8
sql_query = SELECT id, title, body FROM documents \
WHERE id>( SELECT max_doc_id FROM sph_counter WHERE counter_id=1 )
}

# 加在所以test1後
index delta : test1
{
source = delta
path = /path/to/delta
}

添加自動運行腳本:
$cd /usr/local/coreseek/etc/
$vi delta.sh
$/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/sphinx.conf delta --rotate >> /usr/local/coreseek/var/log/delta.log

$vi test1.sh
/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/sphinx.conf --merge test1 delta --rotate >> /usr/local/coreseek/var/log/test1.log

$crontab -e
*/1 * * * * /usr/local/coreseek/etc/delta.sh #每隔一分鐘運行一次
30 2 * * * /usr/local/coreseek/etc/test1.sh #每天半夜2:30運行


保存並對delta.sh/test1.sh設權限 chmod 755;

#重啓crond服務
$service crond stop
$service crond start

接下來可以查看log日誌,或者搜索下delta索引;


附:[url=http://dl.iteye.com/topics/download/714329e2-71db-39d3-9fc8-7ecab523412e]sphinx中文手冊[/url]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章