Sphinx站內搜索
來自: http://my.oschina.net/corwien/blog/626217
一、Sphinx流程
Mysql數據 -》 sphinx -》 索引數據
二、sphinx概述
三、Sphinx使用地方
1、網站中的搜索(站內搜索)
2、系統后臺中的搜索
四、為什么要使用Sphinx
當數據超過100W時,我們需要使用第三方工具,Sphinx。
1、做搜索時當數據量大單純的Mysql搜索比較慢(如果進行了分表會更慢)
如200W數據,查詢記錄中帶某個字的數據:
mysql> select * from article where title like '%孩子';
模糊查詢耗費時間:9.28s
2、搜索時中文分詞
如搜:劉德華,會將劉德華,劉華,馬德華相關的搜索匹配出來。
3、Sphinx快
高速的建立索引(在當代CPU中,峰值性能高達10M/s)
高性能的搜索(在2-4G的文本數據上,平均每次檢索時間小于0.1s)
可處理海量數據
五、獲取Sphinx
官方地址:http://sphinxsearch.com/ ,Sphinx必須安裝在服務器中
Deb packages:
Sphinx requires a few libraries to be installed on Debian/Ubuntu. Use apt-get to download and install these dependencies:
$ sudo apt-get install mysql-client unixodbc libpq5
Now you can install Sphinx:
$ sudo
apt-get install sphinxsearchstart sphinxsearch
root@iZ9:/# sudo service sphinxsearch start
To enable sphinxsearch, edit /etc/default/sphinxsearch and set START=yes
編輯sphinx配置:
root@iZ94j7ehy5oZ:/# vim /etc/default/sphinxsearch
使用命令搜索:
root@iZ94j7:/# whereis sphinxsearch
sphinxsearch: /etc/sphinxsearch // 用來存放sphinx當中的一些配置文件
安裝好后,還會有2個工具,存放在/usr/bin/下邊
root@iZ94j7:/# usr/bin$ indexer 創建索引
root@iZ94j7:/# usr/bin$ searched 后端的進程
六、Sphinx配置
1、嘗試開啟sphinx服務
root@iZ94j7:/usr/share# sudo service sphinxsearch start
Starting sphinxsearch:
// 提示需要先進行配置
Please create an /etc/sphinxsearch/sphinx.conf configuration file.
A template is provided as /etc/sphinxsearch/sphinx.conf.sample.
root@iZ94j7:/usr/share#