0622centos下coreseek安裝及使用方法

Coreseek 中文全文檢索引擎 
Coreseek 是一款中文全文檢索/搜索軟件,以GPLv2許可協議開源發佈,基於Sphinx研發並獨立發佈,專攻中文搜索和信息處理領域,適用於行業/垂直搜索、論壇/站內搜索、數據庫搜索、文檔/文獻檢索、信息檢索、數據挖掘等應用場景,用戶能夠免費下載使用 

一,coreseek 簡介 
官方http://www.coreseek.cn/ 
Coreseek 是一款中文全文檢索/搜索軟件,以GPLv2許可協議開源發佈,基於Sphinx研發並獨立發佈,專攻中文搜索和信息處理領域,適用於行業/垂直搜索、論壇/站內搜索、數據庫搜索、文檔/文獻檢索、信息檢索、數據挖掘等應用場景。商業使用(例如, 嵌入到其餘程序中)須要得到商業受權。 
Coreseek是一個支持中文的全文搜索引擎,意圖爲其餘應用提供高速、低空間佔用、高相關度結果的中文全文搜索能力。CoreSeek能夠很是容易的與SQL數據庫和腳本語言集成。 
在Sphinx發行版本中提供的原生搜索API支持PHP、Python、Perl、Rudy和Java。搜索API很是輕量化,能夠在幾個小時以內移植到新的語言上。第三方API接口和插件提供了對Perl、C#、Haskell、Ruby-on-Rails支持,以及對其餘可能的語言或者框架的支持。 

版本介紹 
Coreseek 3.2 穩定版 
Coreseek 4.1 測式版 
Coreseek 5 最新版 

二,安裝Coreseek 
注:本文是以centos+mysql作爲數據源支持爲基礎的coreseek安裝教程.mysql安裝略過. 

1,下載coreseek 3.2穩定版,下載其餘版本請去官網自行下載 
cd /usr/local/src/ 
wget http://www.coreseek.cn/uploads/csft/3.2/coreseek-3.2.14.tar.gz 
tar xzvf coreseek-3.2.14.tar.gz 
cd coreseek-3.2.14 
安裝coreseek以前須要先安裝須要預裝的軟件:yum install make gcc g++ gcc-c++ libtool autoconf automake imake mysql-devel libxml2-devel expat-devel (注:這是centos 64位 
其餘系統請參考http://www.coreseek.cn/product_install/install_on_bsd_linux/#deps 

2,安裝mmseg 
$ cd mmseg-3.2.14 
$ ./bootstrap #輸出的warning信息能夠忽略,若是出現error則須要解決 
$ ./configure --prefix=/usr/local/mmseg3 
$ make && make install 
$ cd .. 

##若是提示libtool: unrecognized option `--tag=CC' ,請查看libtool問題解決方案 
##安裝完成後,mmseg使用的詞典和配置文件,將自動安裝到/usr/local/mmseg3/etc中 
##中文分詞測試,若是顯示不正常,請檢查當前環境下的locale和UTF-8中文字符顯示設置 
$ /usr/local/mmseg3/bin/mmseg -d /usr/local/mmseg3/etc src/t1.txt 
中文/x 分/x 詞/x 測試/x 
中國人/x 上海市/x 

Word Splite took: 1 ms. 


3,安裝coreseek 
$ cd csft-3.2.14 
##執行configure,進行編譯配置: 
$ 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 

如查提示找不到mysql includes file則使用下面的編譯命令 

./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-includes=/alidata/server/mysql/include/ --with-mysql-libs=/alidata/server/mysql/bin/ 
make && make install 


4,測式coreseek 
cd ../testpack 
$ /usr/local/coreseek/bin/indexer -c etc/csft.conf 
##如下爲正常狀況下的提示信息: 
Coreseek Fulltext 3.2 [ Sphinx 0.9.9-release (r2117)] 
Copyright (c) 2007-2010, 
Beijing Choice Software Technologies Inc (http://www.coreseek.com) 

using config file 'etc/csft.conf'... 
total 0 reads, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg 
total 0 writes, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg 
## 
##csft-4.0版顯示:ERROR: nothing to do. 
## 
$ /usr/local/coreseek/bin/indexer -c etc/csft.conf --all 
##如下爲正常索引所有數據時的提示信息:(csft-4.0版相似) 
Coreseek Fulltext 3.2 [ Sphinx 0.9.9-release (r2117)] 
Copyright (c) 2007-2010, 
Beijing Choice Software Technologies Inc (http://www.coreseek.com) 

using config file 'etc/csft.conf'... 
indexing index 'xml'... 
collected 3 docs, 0.0 MB 
sorted 0.0 Mhits, 100.0% done 
total 3 docs, 7585 bytes 
total 0.075 sec, 101043 bytes/sec, 39.96 docs/sec 
total 2 reads, 0.000 sec, 5.6 kb/call avg, 0.0 msec/call avg 
total 7 writes, 0.000 sec, 3.9 kb/call avg, 0.0 msec/call avg 

$ /usr/local/coreseek/bin/indexer -c etc/csft.conf xml 
##如下爲正常索引指定數據時的提示信息:(csft-4.0版相似) 
Coreseek Fulltext 3.2 [ Sphinx 0.9.9-release (r2117)] 
Copyright (c) 2007-2010, 
Beijing Choice Software Technologies Inc (http://www.coreseek.com) 

using config file 'etc/csft.conf'... 
indexing index 'xml'... 
collected 3 docs, 0.0 MB 
sorted 0.0 Mhits, 100.0% done 
total 3 docs, 7585 bytes 
total 0.069 sec, 109614 bytes/sec, 43.35 docs/sec 
total 2 reads, 0.000 sec, 5.6 kb/call avg, 0.0 msec/call avg 
total 7 writes, 0.000 sec, 3.9 kb/call avg, 0.0 msec/call avg 

$ /usr/local/coreseek/bin/search -c etc/csft.conf 
##如下爲正常測試搜索時的提示信息:(csft-4.0版相似) 
Coreseek Fulltext 3.2 [ Sphinx 0.9.9-release (r2117)] 
Copyright (c) 2007-2010, 
Beijing Choice Software Technologies Inc (http://www.coreseek.com) 

using config file 'etc/csft.conf'... 
index 'xml': query '': returned 3 matches of 3 total in 0.093 sec 

displaying matches: 
1. document=1, weight=1, published=Thu Apr 1 22:20:07 2010, author_id=1 
2. document=2, weight=1, published=Thu Apr 1 23:25:48 2010, author_id=1 
3. document=3, weight=1, published=Thu Apr 1 12:01:00 2010, author_id=2 

words: 


$ /usr/local/coreseek/bin/search -c etc/csft.conf -a Twittter和Opera都提供了搜索服務 
##如下爲正常測試搜索關鍵詞時的提示信息:(csft-4.0版相似) 
Coreseek Fulltext 3.2 [ Sphinx 0.9.9-release (r2117)] 
Copyright (c) 2007-2010, 
Beijing Choice Software Technologies Inc (http://www.coreseek.com) 

using config file 'etc/csft.conf'... 
index 'xml': query 'Twittter和Opera都提供了搜索服務 ': returned 3 matches of 3 total in 0.038 sec 

displaying matches: 
1. document=3, weight=24, published=Thu Apr 1 12:01:00 2010, author_id=2 
2. document=1, weight=4, published=Thu Apr 1 22:20:07 2010, author_id=1 
3. document=2, weight=3, published=Thu Apr 1 23:25:48 2010, author_id=1 

words: 
1. 'twittter': 1 documents, 3 hits 
2. '和': 3 documents, 15 hits 
3. 'opera': 1 documents, 25 hits 
4. '都': 2 documents, 4 hits 
5. '提供': 0 documents, 0 hits 
6. '了': 3 documents, 18 hits 
7. '搜索': 2 documents, 5 hits 
8. '服務': 1 documents, 1 hits 

$ /usr/local/coreseek/bin/searchd -c etc/csft.conf 
##如下爲正常開啓搜索服務時的提示信息:(csft-4.0版相似) 
Coreseek Fulltext 3.2 [ Sphinx 0.9.9-release (r2117)] 
Copyright (c) 2007-2010, 
Beijing Choice Software Technologies Inc (http://www.coreseek.com) 

using config file 'etc/csft.conf'... 
listening on all interfaces, port=9312 

三,配置coreseek支持mysql數據源 

1,配置csft_mysql.conf文件 
複製mysql配置文件到coreseek安裝目錄etc/下(好比/usr/local/coreseek/etc/) 
cp /usr/local/src/coreseek-3.2.14/testpack/etc/csft_mysql.conf /usr/local/coreseek/etc/ 
cd /usr/local/coreseek/etc/ 
vi csft_mysql.conf 
下面加紅部分是須要你本身配置的 

官方參考文檔:數據源配置:mysql數據源 http://www.coreseek.cn/products-install/datasource/

其餘數據源請參考官方
==============================================================
#源定義
source phperz
{
    type                    = mysqlphp

    sql_host                = localhost
    sql_user                = root
    sql_pass                = xxxx
    sql_db                    = phperz
    sql_port                = 3306
    sql_query_pre            = SET NAMES utf8html

    sql_query                = SELECT id,title,descs,status from article
                                                              #sql_query第一列id需爲整數
                                                              #title、content做爲字符串/文本字段,被全文索引
    sql_attr_uint            = status           #從SQL讀取到的值必須爲整數
    #sql_attr_timestamp        = date_added #從SQL讀取到的值必須爲整數,做爲時間屬性mysql

    sql_query_info_pre      = SET NAMES utf8                                        #命令行查詢時,設置正確的字符集
    sql_query_info            = SELECT * FROM article WHERE id=$id #命令行查詢時,從數據庫讀取原始數據信息
}linux

#index定義
index phperz
{
    source            = phperz             #對應的source名稱
    path            =  /usr/local/coreseek/var/data/phperz #請修改成實際使用的絕對路徑,例如:/usr/local/coreseek/var/...
    docinfo            = extern
    mlock            = 0
    morphology        = none
    min_word_len        = 1
    html_strip                = 0c++

    #中文分詞配置,詳情請查看:http://www.coreseek.cn/products-install/coreseek_mmseg/
    charset_dictpath = /usr/local/mmseg3/etc/ #BSD、Linux環境下設置,/符號結尾
    #charset_dictpath = etc/                             #Windows環境下設置,/符號結尾,最好給出絕對路徑,例如:C:/usr/local/coreseek/etc/...
    charset_type        = zh_cn.utf-8
}
#全局index定義
indexer
{
    mem_limit            = 128M
}sql

#searchd服務定義
searchd
{
    listen                  =   9312
    read_timeout        = 5
    max_children        = 30
    max_matches            = 1000
    seamless_rotate        = 0
    preopen_indexes        = 0
    unlink_old            = 1
    pid_file = /usr/local/coreseek/var/log/searchd_mysql.pid  #請修改成實際使用的絕對路徑,例如:/usr/local/coreseek/var/...
    log = /usr/local/coreseek/var/log/searchd_mysql.log        #請修改成實際使用的絕對路徑,例如:/usr/local/coreseek/var/...
    query_log = /usr/local/coreseek/var/log/query_mysql.log #請修改成實際使用的絕對路徑,例如:/usr/local/coreseek/var/...
}
==============================================================數據庫

2,創建索引
路經部分須要改爲你本身的地址
/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_mysql.conf --all
bootstrap

可能出現的錯誤
ERROR: index 'phperz': sql_connect: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) (DSN=mysql://root:***@localhost:3306/phperz).
這是由於mysql的sock文件路經不正確致使的.
確認一下你的mysql.sock路經,創建一個軟鏈接,好比
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
centos

四,coreseek+php使用方式
複製安裝止錄下的/usr/local/src/coreseek-3.2.14/testpack/api/sphinxapi.php文件到你的項目裏
你的程序裏include sphinxapi.php
php使用方法見/usr/local/src/coreseek-3.2.14/testpack/api/test.php
另附個人使用方法:
===============================================================
$wd    =    trim($_GET['wd']);
include_once(JF_PATH."/config/sph_cfg.php");
include_once(JF_PATH."/include/sphinxapi.php");
$cl = new SphinxClient();
$cl->SetServer(SPH_SERVER_HOST, SPH_SERVER_POST);
$cl->SetConnectTimeout(3);
$cl->SetArrayResult(true);
$cl->SetMatchMode(1);
$cl->SetFilter("status", array(1));
$cl->SetLimits(0, 10);
$res = $cl->Query($wd, "phperz_www");
api

if ($res['matches']) {
$rownum = $res['total'];
foreach ($res['matches'] as $k => $v) {
$re = $this->db->get_one("select * from article where id=".$v['id']);
if (!empty($re)) {
    $list[] = $re;
}
}
}
print_r($list);
===============================================================

五,coreseek平常維護

啓動
/usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/csft_mysql.conf
中止
/usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/csft_mysql.conf --stop
創建索引
/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_mysql.conf --all
重建索引
/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_mysql.conf --all --rotate

你須要把啓動命令加到開機自啓動裏
把重建索引命令加到計劃任務裏天天執行

本文爲phperz原創,轉載請註明出處.

 

 

 

-- 關於中文分詞整理最終的安裝步驟http://www.jb51.net/os/RedHat/462185.html 安裝SPHINX的方法https://www.ibm.com/developerworks/cn/opensource/os-sphinx/ SPHINX的理解http://www.jb51.net/os/RedHat/462185.html coreseek中文分詞的安裝http://www.cnblogs.com/qcfeng/p/7063512.html 經過熱插件的方式安裝SPHINX