一、安裝
關於coreseek的相關介紹,可通過網址:http://www.coreseek.cn 學些。下面直接進入主題。
1、解壓
#tar -zxvf coreseek-4.1-beta.tar.gz
#cd coreseek-4.1-beta
2、安裝中文分詞包
進入中文分詞安裝目錄
#cd mmseg-3.2.14/
安裝中文分詞包,我的路徑是/share_folder/source/sphinx/mmseg/
# ./configure --prefix=/share_folder/source/sphinx/mmseg/
#make && make install
注意,在./configure的時候,可能會報:
config.status: error: cannot find input file: src/Makefile.in
直接運行如下命令(系統中如果沒有automake工具,得安裝):
#automake
再次運行./configure 即可進行配置了,安裝好後,進入安裝目錄的bin目錄下,可運行
mmseg文件。
3、把sphinx與coreseek中文分詞包結合起來
進入sphinx目錄
#cd /share_folder/source/sphinx/coreseek-4.1-beta/csft-4.1
#./configure --prefix=/share_folder/source/sphinx/csft/ \
--with-mmseg=/share_folder/source/sphinx/mmseg/bin/ \
--with-mmseg-includes=/share_folder/source/sphinx/mmseg/include/mmseg \
--with-mmseg-libs=/share_folder/source/sphinx/mmseg/lib/
#make && make install
二、生成數據源
coreseek自帶用於mysql測試的數據庫表數據,在csft安裝的etc目錄下(example.sql)。
運行如下命令:
#mysql -u root < /share_folder/source/sphinx/csft/etc/example.sql
在mysql數據庫(test)的表documents中將生成測試用數據,可以用sql語句去數據庫
中進行查詢。
三、coreseek配置文件csft.conf配置
1、拷貝配置文件,coreseek中的默認配置文件名是csft.conf
#cp /share_folder/source/sphinx/csft/etc/sphinx.conf.dist csft.conf
2、配置支持中文分詞,此處只寫出更改的配置。
該配置文件中,主要由4個部分組成:
sourece --------------------配置數據源
index --------------------配置索引
indexer --------------------配置索引內存相關
searchd --------------------配置索引服務器
在index部分:
#stopwords = G:\data\stopwords.txt
#wordforms = G:\data\wordforms.txt
#exceptions = /data/exceptions.txt
#支持中文分詞
charset_type =zh_cn.utf-8
#安裝中文分詞的路徑
charset_dictpath =/share_folder/source/sphinx/mmseg/etc/
四、生成索引
安裝好源碼後,在sphinx安裝目錄下(/share_folder/source/sphinx/csft/bin),有3個工具
文件:
indexer -------------------------生成索引命令
search --------------------------測試查詢命令
searchd --------------------------搜索引擎服務器,測試api的時候,需要啓動這個命令
1、建立索引
#cd /share_folder/source/sphinx/csft/bin
#./indexer test1
生成索引的時候報:
./indexer: error while loading shared libraries: libmysqlclient.so.15: cannot open shared \
object file: No such file or directory
這主要是因爲你安裝了一些庫後,沒有能夠配置相應的環境變量,可以通過連接的
式修正這個問題。
2、測試搜索
#./search test (搜索關鍵字 test)
不出錯的話,將得到如下結果:
[root@localhost bin]# ./search test
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 '/share_folder/source/sphinx/csft/etc/csft.conf'...
index 'test1': query 'test ': returned 3 matches of 3 total in 0.030 sec
displaying matches:
1. document=1, weight=2, group_id=1, date_added=Sun Feb 24 02:23:37 2013
id=1
group_id=1
group_id2=5
date_added=2013-02-24 02:23:37
title=test one
content=this is my test document number one. also checking search within phrases.
。。。。。。
words:
1. 'test': 3 documents, 5 hits
index 'test1stemmed': query 'test ': returned 3 matches of 3 total in 0.002 sec
displaying matches:
1. document=1, weight=2, group_id=1, date_added=Sun Feb 24 02:23:37 2013
id=1
group_id=1
group_id2=5
date_added=2013-02-24 02:23:37
title=test one
content=this is my test document number one. also checking search within phrases.
2. document=2, weight=2, group_id=1, date_added=Sun Feb 24 02:23:37 2013
。。。。。。
words:
1. 'test': 3 documents, 5 hits
3、 Api測試
源碼中自帶了幾個版本的api,包括php、java、c語言等api。下面僅以c語言api
爲例。進入/coreseek-3.2.14/csft-3.2.14/目錄,裏面有個api文件夾,libsphinxclient即是
c語言api。編譯api:
#cd libsphinxclient
#./configure
#make
編譯完後,將在該目錄下生成可執行文件test。test.c中是查詢關鍵字test。可在
test_query函數中修改。執行查詢前,先啓動搜索服務器swarchd。
#/share_folder/source/sphinx/csft/bin/searchd (加上 --stop將停止該服務)
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 '/share_folder/source/sphinx/csft/etc/csft.conf'...
listening on all interfaces, port=9312
然後運行可執行文件test,不出錯的話,將顯示查詢結果。查詢的時候,報:
ERROR connection to localhost failed (errno=111, msg=Connection)
我的是沒有把localhost與127.0.0.1映射起來,所以會報這個錯,如下命令可修正。
#echo "127.0.0.1 `hostname` localhost localhost.localdomain" >/etc/hosts
以上,簡單測試結束。