Sphinx是開源的搜索引擎,它支持英文的全文檢索。所以如果單獨搭建Sphinx,你就已經(jīng)可以使用全文索引了。但是往往我們要求的是中文索引,怎么做呢?國人提供了一個可供企業(yè)使用的,基于Sphinx的中文全文檢索引擎。也就是說Coreseek實際上的內(nèi)核還是Sphinx。那么他們的版本對應(yīng)呢?
Coreseek發(fā)布了3.2.14版本和4.1版本,其中的3.2.14版本是2010年發(fā)布的,它是基于Sphinx0.9.9搜索引擎的。而4.1版本是2011年發(fā)布的,它是基于Sphinx2.0.2的。Sphinx從0.9.9到2.0.2還是有改變了很多的,有很多功能,比如sql_attr_string等是在0.9.9上面不能使用的。所以在安裝之前請判斷清楚你需要安裝的是哪個版本,在google問題的時候也要弄清楚這個問題的問題和答案是針對哪個版本的。我個人強烈建議使用4.1版本。
網(wǎng)上有一篇文章說的是Sphinx和Coreseek是怎么安裝的,其中它的coreseek安裝這部分使用coreseek-4.1來替換就可以使用了。
詳細(xì)步驟看上面篇文章就理解了,這里說一下我在安裝過程中遇到的幾個問題:
安裝mmseg的時候,./configure出現(xiàn)錯誤:config.status: error: cannot find input file: src/Makefile.in這個時候需要先運行下automake
結(jié)果我運行的時候竟然提示automake的版本不對
所以這個時候,你可能需要去網(wǎng)址下個對應(yīng)的版本(有可能是需要老版本)再來運行
在安裝csrf的時候,文檔提示需要指定mysql,但是我的mysql是yum安裝的,找不到安裝路徑./configure --prefix=/usr/local/coreseek --with-mysql=/usr/local/mysql --with-mmseg=/usr/local/mmseg --with-mmseg-includes=/usr/local/mmseg/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg/lib/
yum安裝的mysql的include和libs文件夾一般是安裝在/usr/include/mysql和/usr/lib64/mysql下面
所以這里的--with-mysql可以使用--with-mysql-includes和--with-mysql-libs來進(jìn)行替換。
./configure --prefix=/usr/local/coreseek --with-mysql-includes=/usr/includes/mysql --with-mysql-libs=/usr/lib64/mysql/ --with-mmseg=/usr/local/mmseg --with-mmseg-includes=/usr/local/mmseg/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg/lib/配置文件提示unknown key: sql_attr_string
如上文,就需要檢查下自己的sphinx版本了
如何安裝php的sphinx擴(kuò)展可以在這里(http://pecl.php.net/package/sphinx)找到sphinx的php擴(kuò)展源碼
注意,使用phpize,configure的時候可能會要求要安裝libsphinxclient,它在coreseek-4.1-beta/csft-4.1/api/libsphinxclient/里面能找到,編譯安裝它以后就可以configure,make,生成動態(tài)so文件了。
如何配置sphinx.conf配置文件最復(fù)雜的部分就是sphinx.conf配置文件的配置了,里面的注釋代碼非常多,我建議使用的時候把注釋代碼去掉,我貼出自己使用的最簡單的一個成功的配置文件:
source src1{ type = mysql sql_host = localhost sql_user = yejianfeng sql_pass = test sql_db = mysite sql_port = 3306 # optional, default is 3306 sql_query_pre = SET NAMES utf8 sql_query_pre = SET SESSION query_cache_type=OFF sql_query = select id, id AS id_new,name, name AS name_query,descr, descr AS descr_query,city FROM account sql_attr_string = name sql_attr_string = descr sql_query_info = SELECT * FROM account WHERE id=$id}source src1throttled : src1{ sql_ranged_throttle = 100}index test1{ source = src1 path = /home/yejianfeng/instance/coreseek/var/data/test1 docinfo = extern mlock = 0 morphology = none min_word_len = 1 charset_type = zh_cn.utf-8 charset_dictpath = /home/yejianfeng/instance/mmseg/etc/ html_strip = 0}indexer{ mem_limit = 256M}searchd{ listen = 9312 listen = 9306:mysql41 log = /home/yejianfeng/instance/coreseek/var/log/searchd.log query_log = /home/yejianfeng/instance/coreseek/var/log/query.log read_timeout = 5 client_timeout = 300 max_children = 30 pid_file = /home/yejianfeng/instance/coreseek/var/log/searchd.pid max_matches = 1000 seamless_rotate = 1 preopen_indexes = 1 unlink_old = 1 mva_updates_pool = 1M max_packet_size = 8M max_filters = 256 max_filter_values = 4096}php調(diào)用SphinxClient的例子如下:
首先要確保已經(jīng)啟動了searchd
[yejianfeng@AY130416142121702aac etc]$ ps aux|grep searchd501 30897 0.0 0.0 60824 1396 pts/2 S 17:19 0:00 /home/yejianfeng/instance/coreseek/bin/searchd -c /home/yejianfeng/instance/coreseek/etc/sphinx.conf501 30999 0.0 0.0 103232 856 pts/2 S+ 18:10 0:00 grep searchd
php提供的調(diào)用SphinxClient的接口
<?php$s = new SphinxClient;$s->setServer("localhost", 9312);$s->setArrayResult(true);$s->setSelect();$s->setMatchMode(SPH_MATCH_ALL);$result = $s->query('美女', 'test1');print_r($result);PHP編程
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。
新聞熱點
疑難解答