coreseek java_coreseek 安装及使用方法详解
coreseek 安裝及使用
一般站點(diǎn)都需要搜索功能,如果是php+mysql站點(diǎn),建議選擇coreseek,如果是java站點(diǎn)建議使用lucene,coreseek 是一款很好的中文全文檢索/搜索軟件,支持高速建立索引、有很強(qiáng)的擴(kuò)展性、支持分布式檢索,支持不同的搜索模式(’完全匹配’,’短語匹配’,’任一匹配’)。
logo1
如果下面的過程遇到問題,請參考 coreseek安裝遇到的錯(cuò)誤和問題解決方案 我把安裝和配置遇到的常見問題和解決辦法都總結(jié)在那里了。
一、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??? #現(xiàn)實(shí)的是中文的內(nèi)容
/usr/local/mmseg3/bin/mmseg -d /usr/local/mmseg3/etc var/test/test.xml #顯示xml文件內(nèi)容
/usr/local/coreseek/bin/indexer -c etc/csft.conf --all #建立索引
/usr/local/coreseek/bin/search -c etc/csft.conf # 進(jìn)行搜索
二、coreseek配置和使用
1:配置example.conf文件
cd /usr/local/coreseek/etc
cp sphinx-min.conf.dist example.conf
對example.conf的配置進(jìn)行改造,變成我們所需的配置文件。
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 #不管表的主鍵叫什么,查出來的結(jié)果都是為id
sql_query_info_pre????? = SET NAMES utf8????????????????????? #命令行查詢時(shí),設(shè)置正確的字符集
sql_query_info????????? = SELECT * FROM table WHERE id=$id? LIMIT 100#命令行查詢時(shí),從數(shù)據(jù)庫讀取原始數(shù)據(jù)信息
}
#index定義
index example
{
source??????????? = example???????????? #對應(yīng)的source名稱
path??????????? = /usr/local/coreseek/var/data/example/ #請修改為實(shí)際使用的絕對路徑
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環(huán)境下設(shè)置,/符號(hào)結(jié)尾
#charset_dictpath = etc/? #Windows環(huán)境下設(shè)置,/符號(hào)結(jié)尾,最好給出絕對路徑,
charset_type??????? = zh_cn.utf-8
}
#全局index定義
indexer
{
mem_limit??????????? = 128M
}
#searchd服務(wù)定義
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? #請修改為實(shí)際使用的絕對路徑,例如:/usr/local/coreseek/var/...
log = /usr/local/coreseek/var/log/searchd_example.log? #請修改為實(shí)際使用的絕對路徑,例如:/usr/local/coreseek/var/...
query_log = /usr/local/coreseek/var/log/query_example.log #請修改為實(shí)際使用的絕對路徑,例如:/usr/local/coreseek/var/...
}
2:開啟searchd服務(wù) (這點(diǎn)很重要)
coreseek剛安裝后searchd服務(wù)是沒開啟的,需要先開啟,不然創(chuàng)建索引的時(shí)候會(huì)出錯(cuò)。
先在 /usr/local/src/coreseek/var/log下創(chuàng)建一個(gè)searchd_example.pid文件,然后執(zhí)行下面的代碼:
/usr/local/coreseek/bin/searchd --config /usr/local/coreseek/etc/example.conf
3:創(chuàng)建索引
/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/example.conf --all --rotate
出現(xiàn)下面的提示:
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已經(jīng)可以使用了。
可以把創(chuàng)建索引的命令寫入crontab里面進(jìn)行定時(shí),實(shí)時(shí)更新索引。
4:php 和 coreseek 結(jié)合進(jìn)行查詢
先下載sphinxapi,然后文件引入結(jié)合php進(jìn)行查詢,下面更多參數(shù)的詳解和配置,可以參考 coreseek api php手冊
require_once('sphinxapi');
$s = new SphinxClient();
$s->SetServer('127.0.0.1','9312'); //設(shè)置searchd的主機(jī)名和TCP端口
$s->SetConnectTimeout(1); // 設(shè)置連接超時(shí)
$s->SetMatchMode(SPH_MATCH_BOOLEAN); //設(shè)置全文查詢的匹配模式
$page_size=20;//自己定義的頁數(shù)
$s->SetLimits($start,$page_size); //設(shè)置返回結(jié)果集偏移量和數(shù)目
$s->SetSortMode( SPH_SORT_EXTENDED,"good_count DESC, @id DESC" ); // 設(shè)置排序
$s->SetArrayResult(true);//控制搜索結(jié)果集的返回格式
$res = $s->Query($keyword,'*');// 執(zhí)行搜索查詢
$res_list = $res['matches'];
安裝遇到的錯(cuò)誤和問題解決方案
1、測試mmseg分詞的時(shí)候
執(zhí)行
/usr/local/coreseek/bin/indexer -c etc/csft.conf --all
提示下面的錯(cuò)誤:
/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
然后運(yùn)行 ldconfig
問題解決
2、執(zhí)行索引的時(shí)候
/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_ttd_search.conf --all --rotate
提示下面的錯(cuò)誤:
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(自己創(chuàng)建的文件)的 source源 加入下面的代碼
sql_sock?? = /tmp/mysql.sock
3、執(zhí)行索引的時(shí)候,出現(xiàn)的警告,導(dǎo)致索引沒創(chuàng)建成功
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 下創(chuàng)建searchd_ttd_search.pid文件
再執(zhí)行/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_ttd_search.conf –all –rotate
出現(xiàn)了另外一個(gè)警告:
WARNING: failed to scanf pid from pid_file '/usr/local/coreseek/var/log/searchd_ttd_search.pid'.
WARNING: indices NOT rotated.
原因:雖然創(chuàng)建了searchd_ttd_search.pid文件,但是里面沒有寫入進(jìn)程id
解決辦法(根本原因):在執(zhí)行索引之前沒有啟動(dòng)searchd服務(wù),因此執(zhí)行下面的命令
/usr/local/coreseek/bin/searchd --config /usr/local/coreseek/etc/ttd_search.conf
出現(xiàn)了期待已久的成功提示:
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
總結(jié)
以上是生活随笔為你收集整理的coreseek java_coreseek 安装及使用方法详解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android 第一课 Activit
- 下一篇: java面试题28 牛客 下面有关jav