一、安裝coreseekphp
1.1首先升級或安裝系統依賴庫 html
yum install make gcc g++ automake libtool mysql-client libmysqlclient15-dev libxml2-dev libexpat1-dev
1.2下載Coreseek3.2.14mysql
解壓:tar zxvf coreseek-3.2.14.tar.gzlinux
cd coreseek-3.2.14 cd mmseg-3.2.14 #在安裝前首先安裝mmseg插件 ./configure --prefix=/Data/apps/mmseg3
若是報以下錯誤nginx
config.status: creating Makefile config.status: creating src/Makefile config.status: error: cannot find input file: src/Makefile.in
經過安裝autoconf和automake解決sql
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. ------------------------------------------------------------------------
安裝mmsegvim
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了api
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命令查看安裝後的目錄及文件網絡
[root@localhost csft-3.2.14]# ls /Data/apps/coreseek/ bin etc var
二、檢測Coreseek中文分詞
一、cd /Data/tgz/coreseek-3.2.14/testpack/ 二、/Data/apps/mmseg3/bin/mmseg -d /Data/apps/mmseg3/etc var/test/test.xml 三、/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/便可 四、/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
三、配置coreseek並使用
3.一、把實例配置複製到安裝coreseek的etc目錄下
cp /Data/tgz/coreseek-3.2.14/testpack/etc/csft_mysql.conf /Data/apps/coreseek/etc/csft_mysql.conf
3.二、修改配置文件
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.三、創建索引
/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 MB sorted 0.0 Mhits, 100.0% done total 811 docs, 15729 bytes total 0.072 sec, 217260 bytes/sec, 11202.12 docs/sec total 2 reads, 0.000 sec, 14.2 kb/call avg, 0.0 msec/call avg total 7 writes, 0.000 sec, 10.3 kb/call avg, 0.0 msec/call avg
3.四、啓動服務
/Data/apps/coreseek/bin/searchd -c /Data/apps/coreseek/etc/csft_mysql.conf
四、使用sphinx有兩種方法,一種是安裝php的sphinx擴展,第二種是使用sphinx的接口,這裏直接使用sphinx接口
4.一、把sphinxapi.php文件複製到項目目錄
cp api/sphinxapi.php /Data/apps/nginx/html/sphinx/
4.二、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中去。