標籤:命令 word etc mis call 項目 ack mac nts
1、安裝coreseek
1.1首先升級或安裝系統依賴庫
yum install make gcc g++ automake libtool mysql-client libmysqlclient15-dev libxml2-dev libexpat1-dev
1.2下載Coreseek3.2.14
解壓:tar zxvf coreseek-3.2.14.tar.gz
cd coreseek-3.2.14 cd mmseg-3.2.14 #在安裝前首先安裝mmseg外掛程式 ./configure --prefix=/Data/apps/mmseg3
如果報如下錯誤
config.status: creating Makefile config.status: creating src/Makefile config.status: error: cannot find input file: src/Makefile.in
通過安裝autoconf和automake解決
yum -y install autoconf automake aclocal configure.in:26: warning: macro `AM_PROG_LIBTOOL‘ not found in library yum -y install libtool aclocal libtoolize --force libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, `config‘. libtoolize: linking file `config/ltmain.sh‘ libtoolize: Consider adding `AC_CONFIG_MACRO_DIR([m4])‘ to configure.in and libtoolize: rerunning libtoolize, to keep the correct libtool macros in-tree. libtoolize: Consider adding `-I m4‘ to ACLOCAL_AMFLAGS in Makefile.am. automake --add-missing autoconf autoheader make clean
完成上面操作,重新設定即可
./configure --prefix=/Data/apps/mmseg3 ------------------------------------------------------------------------ Configuration: Source code location: . Compiler: gcc Compiler flags: -g -O2 Host System Type: x86_64-redhat-linux-gnu Install path: /Data/apps/mmseg3 See config.h for further configuration information. ------------------------------------------------------------------------
安裝mmseg
make && make install test -z "/Data/apps/mmseg3/etc" || /bin/mkdir -p "/Data/apps/mmseg3/etc" /usr/bin/install -c data/unigram.txt data/uni.lib data/mmseg.ini ‘/Data/apps/mmseg3/etc‘ make[2]: Leaving directory `/Data/tgz/coreseek-3.2.14/mmseg-3.2.14‘ make[1]: Leaving directory `/Data/tgz/coreseek-3.2.14/mmseg-3.2.14‘
1.3安裝完mmseg中文分詞外掛程式後,就可以安裝Coreseek3.2.14了
ln -s /Data/apps/mmseg3/bin/mmseg /bin/mmseg cd .. cd csft-3.2.14/ ./configure --prefix=/Data/apps/coreseek --without-unixodbc --with-mmseg-includes=/Data/apps/mmseg3/include/mmseg/ --with-mmseg-libs=/Data/apps/mmseg3/lib/ --with-mysql make && make install
通過以上步驟,mmseg和Coreseek3.2.14就安裝完成,通過ls命令查看安裝後的目錄及檔案
[[email protected] csft-3.2.14]# ls /Data/apps/coreseek/ bin etc var
2、檢測Coreseek中文分詞
1、cd /Data/tgz/coreseek-3.2.14/testpack/ 2、/Data/apps/mmseg3/bin/mmseg -d /Data/apps/mmseg3/etc var/test/test.xml 3、/Data/apps/coreseek/bin/indexer -c etc/csft.conf --all,如果報錯 Unigram dictionary load Error,修改:/Data/tgz/coreseek-3.2.14/testpack/etc/csft.conf中的charset_dictpath = var/mmseg3/etc/路徑為:charset_dictpath = /Data/apps/mmseg3/etc/即可 4、/Data/apps/coreseek/bin/search -c etc/csft.conf 網路搜尋,報錯如下 index ‘xml‘: search error: failed to open var/data/xml.sph: No such file or directory.
解決如下:
yum install expat-devel* 然後重新安裝sphinx/coreseek 即可
重新執行命令:/Data/apps/coreseek/bin/search -c etc/csft.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 ‘etc/csft.conf‘... index ‘xml‘: query ‘網路搜尋 ‘: returned 1 matches of 1 total in 0.010 sec displaying matches: 1. document=1, weight=1, published=Thu Apr 1 15:20:07 2010, author_id=1 words: 1. ‘網路‘: 1 documents, 1 hits 2. ‘搜尋‘: 2 documents, 5 hits
3、配置coreseek並使用
3.1、把執行個體配置複製到安裝coreseek的etc目錄下
cp /Data/tgz/coreseek-3.2.14/testpack/etc/csft_mysql.conf /Data/apps/coreseek/etc/csft_mysql.conf
3.2、修改設定檔
vim /Data/apps/coreseek/etc/csft_mysql.conf
source mysql{ type = mysql sql_host = localhost sql_user = test sql_pass = root sql_db = kp_account sql_port = 3306 sql_query_pre = SET NAMES utf8 sql_query = SELECT goods_id, goods_id as gid, goods_name, add_time FROM fc_goods #sql_query第一列id需為整數 #title、content作為字串/文字欄位,被全文索引 sql_attr_uint = gid #從SQL讀取到的值必須為整數 sql_attr_timestamp = add_time #從SQL讀取到的值必須為整數,作為時間屬性 sql_query_info_pre = SET NAMES utf8 #命令列查詢時,設定正確的字元集 sql_query_info = SELECT * FROM documents WHERE id=$id #命令列查詢時,從資料庫讀取未經處理資料資訊}#index定義index mysql{ source = mysql #對應的source名稱 path = /Data/apps/coreseek/var/data/mysql #請修改為實際使用的絕對路徑,例如:/usr/local/coreseek/var/... 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 = /Data/apps/mmseg3/etc/ #charset_dictpath = etc/ #Windows環境下設定,/符號結尾,最好給出絕對路徑,例如:C:/usr/local/coreseek/etc/... charset_type = zh_cn.utf-8}#全域index定義indexer{ mem_limit = 128M}#searchd服務定義searchd{ listen = 9312 read_timeout = 5 max_children = 30 max_matches = 1000 seamless_rotate = 0 preopen_indexes = 0 unlink_old = 1 pid_file = /Data/apps/coreseek/var/log/searchd_mysql.pid #請修改為實際使用的絕對路徑,例如:/usr/local/coreseek/var/... log = /Data/apps/coreseek/var/log/searchd_mysql.log #請修改為實際使用的絕對路徑,例如:/usr/local/coreseek/var/... query_log = /Data/apps/coreseek/var/log/query_mysql.log #請修改為實際使用的絕對路徑,例如:/usr/local/coreseek/var/...}
儲存
3.3、建立索引
/Data/apps/coreseek/bin/indexer -c /Data/apps/coreseek/etc/csft_mysql.conf --all
建立成功後提示
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 ‘/Data/apps/coreseek/etc/csft_mysql.conf‘...indexing index ‘mysql‘...collected 811 docs, 0.0 MBsorted 0.0 Mhits, 100.0% donetotal 811 docs, 15729 bytestotal 0.072 sec, 217260 bytes/sec, 11202.12 docs/sectotal 2 reads, 0.000 sec, 14.2 kb/call avg, 0.0 msec/call avgtotal 7 writes, 0.000 sec, 10.3 kb/call avg, 0.0 msec/call avg
3.4、啟動服務
/Data/apps/coreseek/bin/searchd -c /Data/apps/coreseek/etc/csft_mysql.conf
4、使用sphinx有兩種方法,一種是安裝php的sphinx擴充,第二種是使用sphinx的介面,這裡直接使用sphinx介面
4.1、把sphinxapi.php檔案複製到項目目錄
cp api/sphinxapi.php /Data/apps/nginx/html/sphinx/
4.2、php調用sphinx介面進行搜尋
<?php require("sphinxapi.php"); $sphinx = new SphinxClient(); $sphinx->setServer("127.0.0.1", 9312); $keyword = $_GET[‘keyword‘] ? $_GET[‘keyword‘] : ‘輪胎‘; $res = $sphinx->query($keyword, ‘mysql‘); print_r($res);
運行結果:
Array ( [error] => [warning] => [status] => 0 [fields] => Array ( [0] => goods_name ) [attrs] => Array ( [gid] => 1 [add_time] => 2 ) [matches] => Array ( [1] => Array ( [weight] => 1 [attrs] => Array ( [gid] => 1 [add_time] => 1411609439 ) ) [2] => Array ( [weight] => 1 [attrs] => Array ( [gid] => 2 [add_time] => 1411610728 ) ) [3] => Array ( [weight] => 1 [attrs] => Array ( [gid] => 3 [add_time] => 1411610941 ) ) [4] => Array ( [weight] => 1 [attrs] => Array ( [gid] => 4 [add_time] => 1411611452 ) ) [5] => Array ( [weight] => 1 [attrs] => Array ( [gid] => 5 [add_time] => 1411612148 ) ) [6] => Array ( [weight] => 1 [attrs] => Array ( [gid] => 6 [add_time] => 1411670735 ) ) [7] => Array ( [weight] => 1 [attrs] => Array ( [gid] => 7 [add_time] => 1411670863 ) ) [8] => Array ( [weight] => 1 [attrs] => Array ( [gid] => 8 [add_time] => 1411671000 ) ) [9] => Array ( [weight] => 1 [attrs] => Array ( [gid] => 9 [add_time] => 1411671203 ) ) [10] => Array ( [weight] => 1 [attrs] => Array ( [gid] => 10 [add_time] => 1411671953 ) ) [11] => Array ( [weight] => 1 [attrs] => Array ( [gid] => 11 [add_time] => 1411672386 ) ) [12] => Array ( [weight] => 1 [attrs] => Array ( [gid] => 12 [add_time] => 1411672846 ) ) [13] => Array ( [weight] => 1 [attrs] => Array ( [gid] => 13 [add_time] => 1411673187 ) ) [15] => Array ( [weight] => 1 [attrs] => Array ( [gid] => 15 [add_time] => 1411675395 ) ) [16] => Array ( [weight] => 1 [attrs] => Array ( [gid] => 16 [add_time] => 1411675806 ) ) [17] => Array ( [weight] => 1 [attrs] => Array ( [gid] => 17 [add_time] => 1411675957 ) ) [18] => Array ( [weight] => 1 [attrs] => Array ( [gid] => 18 [add_time] => 1411676124 ) ) [19] => Array ( [weight] => 1 [attrs] => Array ( [gid] => 19 [add_time] => 1411676262 ) ) [21] => Array ( [weight] => 1 [attrs] => Array ( [gid] => 21 [add_time] => 1411676661 ) ) [22] => Array ( [weight] => 1 [attrs] => Array ( [gid] => 22 [add_time] => 1411676864 ) ) ) [total] => 49 [total_found] => 49 [time] => 0.017 [words] => Array ( [汽車] => Array ( [docs] => 49 [hits] => 57 ) ) )
小結:到此,就已經基本整合到php當中了,接下來就整合到ThinkPHP中去。
coreseek+sphinx+mysql+thinkphp整合