sphinx基礎

安裝sphinx
1)下載對應版本的源:wget http://sphinxsearch.com/downloads/release/
2)解壓:tar zxvf sphinx-xx
3)進入目錄內:cd sphinx-xx
4)配置:./configure --prefix=須要安裝到哪裏 --with-mysql=mysql的安裝路徑
5)編譯安裝:make && make installphp

sphinx命令
indexer 建立索引
search 命令行搜索
search 索引名
searchd 啓動進程mysql

配置sphinx(安裝目錄etc)
1)複製配置文件:cp sphinx.conf.dist sphinx.conf
2)修改配置文件(重要):
主數據源:
source main{
type=mysql #數據庫類型
sql_host=localhost #MySQL主機IP
sql_user=root #MySQL用戶名
sql_pass= #MySQL密碼
sql_db= #MySQL數據庫
sql_port=3306 #MySQL端口
sql_sock= #指定sock文件
sql_query_pre=SET NAMES UTF8 #MySQL檢索編碼
sql_query_pre=SET SESSION query_cache_type=OFF #關閉緩存
sql_query=select * #獲取數據的SQL語句
sql_query_info = #
}
增量數據源:
source delta:main{}
主數據索引:
index main{
source=main #索引的數據源來源
path=安裝路徑/sphinx/var/data/main #索引存放路徑
charset_type=utf-8 #編碼
charset_table=* #打開該註釋,編碼結構
}
增量數據索引:
index delta:main{}
分佈式索引:
index dist1{}
索引器(2g內存建議分配256m):
indexer{
mem_limit=分配空間M
}
服務進程:
searchd{
listen= #端口 默認不用修改
}web

建立索引(indexer):
-c 指定配置文件
--all 對全部索引從新編制索引
--rotate 用於輪換索引,在不中止服務的時候增長索引
--merge 合併索引,把增量索引合併到主索引 sql

coreseek安裝:
1)下載對應版本的源:wget http://www.coreseek.cn/uploads/csft/4.0/coreseek-4.1-beta.tar.gz
2)解壓:tar zxvf coreseek-xx
3)進入目錄內:cd coreseek-xx/mmseg-xx 先安裝中文分詞
4)配置:./configure --prefix=須要安裝到哪裏
若是出錯執行:automake,而後繼續第4步
5)編譯安裝:make && make install
6)以後安裝coreseek,先進入coreseek目錄:cd ../csft-xx/
7)配置:./configure --prefix=須要安裝到哪裏 --width-mysql=MySQL安裝的目錄 --width-mmseg=MmSEG安裝的目錄 --with-mmseg-includes=MmSEG安裝的庫目錄在include/mmseg/級別 --with-mmseg-libs=MmSEG安裝的庫目錄
8)編譯安裝:make && make install數據庫

coreseek配置:
1)複製配置文件:cp sphinx.conf.dist csft.conf
2)修改配置文件(重要)以前sphinx中的均需修改,還有一些獨自修改的特性:
index main{
#註釋一下語句
#stopwords=路徑
#wordforms=路徑
#exceptions=路徑
#charset_type=sbcs
#添加下面語句,可把中文分詞加入到配置文件中
charset_type=zh_cn.uft-8
charset_dictpath=mmseg安裝目錄的etc下
}api

PHP使用Sphinx必要條件:
1)啓動coreseek並在後臺執行:在coreseek的bin目錄下執行:./searchd 默認端口9312。
2)加載sphinx模塊:wget http://pecl.php.net/get/sphinx-1.1.0.tgz
3)解壓:tar zxvf sphinx-xx
4)進入目錄內:cd sphinx-xx
5)生成configure:/usr/local/webserver/php/bin/phpize
5-1)安裝libsphinxclient:在最初解壓的程序包中進入csft-xx/api/libsphinxclient/目錄
5-2)./configure
5-3)make && make install
6)返回以前目錄而後配置:./configure --width-php-config=安裝路徑下的/bin/php-config --with-sphinx
7)make && make install數組

PHP開發Sphinx:
$sphinx=new SphinxClient();
$sphinx->SetServer("localhost",9312);
$sphinx->SetMatchMode(SPH_MATCH_ANY);//分詞
//$sphinx->SetLimits(0,0);
$result=$sphinx->query("詞","哪一個索引可用*");
$sphinx->buildExcerpts("文檔數組","索引","關鍵詞",$opts)//高亮緩存

相關文章
相關標籤/搜索