創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供潁上網(wǎng)站建設(shè)、潁上做網(wǎng)站、潁上網(wǎng)站設(shè)計(jì)、潁上網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、潁上企業(yè)網(wǎng)站模板建站服務(wù),十多年潁上做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
Sphinx是由俄羅斯人Andrew Aksyonoff開發(fā)的一個(gè)全文檢索引擎。意圖為其他應(yīng)用提供高速、低空間占用、高結(jié)果 相關(guān)度的全文搜索功能。Sphinx可以非常容易的與SQL數(shù)據(jù)庫(kù)和腳本語(yǔ)言集成。當(dāng)前系統(tǒng)內(nèi)置MySQL和PostgreSQL 數(shù)據(jù)庫(kù)數(shù)據(jù)源的支持,也支持從標(biāo)準(zhǔn)輸入讀取特定格式 的XML數(shù)據(jù)。
Sphinx的特性如下:
a) 高速的建立索引(在當(dāng)代CPU上,峰值性能可達(dá)到10 MB/秒);
b) 高性能的搜索(在2 – 4GB 的文本數(shù)據(jù)上,平均每次檢索響應(yīng)時(shí)間小于0.1秒);
c) 可處理海量數(shù)據(jù)(目前已知可以處理超過100 GB的文本數(shù)據(jù), 在單一CPU的系統(tǒng)上可處理100 M 文檔);
d) 提供了優(yōu)秀的相關(guān)度算法,基于短語(yǔ)相似度和統(tǒng)計(jì)(BM25)的復(fù)合Ranking方法;
e) 支持分布式搜索;
f) 支持短語(yǔ)搜索
g) 提供文檔摘要生成
h) 可作為MySQL的存儲(chǔ)引擎提供搜索服務(wù);
i) 支持布爾、短語(yǔ)、詞語(yǔ)相似度等多種檢索模式;
j) 文檔支持多個(gè)全文檢索字段(最大不超過32個(gè));
k) 文檔支持多個(gè)額外的屬性信息(例如:分組信息,時(shí)間戳等);
l) 支持?jǐn)嘣~;
雖然mysql的MYISAM提供全文索引,但是性能卻不敢讓人恭維,另外數(shù)據(jù)庫(kù)畢竟不是很善于做這樣的事情,我們需要把這些活讓給更適合的程序去做,減少數(shù)據(jù)庫(kù)的壓力。因此采用Sphinx來做mysql的全文索引工具是一個(gè)很好的選擇。這個(gè)星期主要來學(xué)習(xí)這個(gè)這個(gè)工具的使用,下面將學(xué)習(xí)過程大致的記錄一下,做個(gè)備忘,也希望能對(duì)學(xué)習(xí)這個(gè)工具的其他朋友有所啟發(fā)。
安裝sphinx
wget http://sphinxsearch.com/files/sphinx-2.2.11-release.tar.gz tar -xf sphinx-2.2.11-release.tar.gz && cd sphinx-2.2.11-release ./configure --prefix=/usr/local/spinx --with-mysql make && make install ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/ libsphinxclient 安裝(PHP模塊需要) cd api/libsphinxclient ./configure –prefix=/usr/local/sphinx make && make install
2.安裝php擴(kuò)展
wget http://pecl.php.net/get/sphinx-1.3.0.tgz tar zxf sphinx-1.3.3.tgz && cd sphinx-1.3.3 ./configure --with-php-config=/usr/local/php/bin/php-config --with-sphinx=/usr/local/sphinx/ make && make install
3.創(chuàng)建配置文件
cp /usr/local/sphinx/etc/sphinx-min.conf.dist /usr/local/sphinx/etc/sphinx.conf
# # Minimal Sphinx configuration sample (clean, simple, functional) # source src1 { type = mysql sql_host = localhost sql_user = root sql_pass = www.123 sql_db = test sql_port = 3306 # optional, default is 3306 sql_query = \ SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content \ FROM documents sql_attr_uint = group_id sql_attr_timestamp = date_added } index test1 { source = src1 path = /usr/local/spinx/var/data/test1 } indexer { mem_limit = 32M } searchd { listen = 9312 listen = 9306:mysql41 log = /usr/local/spinx/var/log/searchd.log query_log = /usr/local/spinx/var/log/query.log read_timeout = 5 max_children = 30 pid_file = /usr/local/spinx/var/log/searchd.pid seamless_rotate = 1 preopen_indexes = 1 unlink_old = 1 workers = threads # for RT to work binlog_path = /usr/local/spinx/var/data }
4.創(chuàng)建索引并啟動(dòng)
/usr/local/spinx/bin/indexer -c /usr/local/spinx/etc/sphinx.conf --all /usr/local/spinx/bin/searchd -c /usr/local/spinx/etc/sphinx.conf
5.查詢驗(yàn)證
cd /root/sphinx-2.2.11-release/api python test.py test DEPRECATED: Do not call this method or, even better, use SphinxQL instead of an API Query 'test ' retrieved 3 of 3 matches in 0.000 sec Query stats: 'test' found 5 times in 3 documents Matches: 1. doc_id=1, weight=2, group_id=1, date_added=2016-11-30 01:21:20 2. doc_id=2, weight=2, group_id=1, date_added=2016-11-30 01:21:20 3. doc_id=4, weight=1, group_id=2, date_added=2016-11-30 01:21:20
mysql> select * from documents; +----+----------+-----------+---------------------+-----------------+---------------------------------------------------------------------------+ | id | group_id | group_id2 | date_added | title | content | +----+----------+-----------+---------------------+-----------------+---------------------------------------------------------------------------+ | 1 | 1 | 5 | 2016-11-30 01:21:20 | test one | this is my test document number one. also checking search within phrases. | | 2 | 1 | 6 | 2016-11-30 01:21:20 | test two | this is my test document number two | | 3 | 2 | 7 | 2016-11-30 01:21:20 | another doc | this is another group | | 4 | 2 | 8 | 2016-11-30 01:21:20 | doc number four | this is to test groups | +----+----------+-----------+---------------------+-----------------+---------------------------------------------------------------------------+
參考網(wǎng)址: http://blog.csdn.net/wangjiuwang/article/details/52002172
http://www.cnblogs.com/findgor/p/5644540.html
http://www.sphinxsearch.org/sphinx-faq
網(wǎng)站標(biāo)題:LNMP+sphinx實(shí)現(xiàn)大數(shù)據(jù)秒查
網(wǎng)站地址:http://chinadenli.net/article44/jsgoee.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、網(wǎng)站策劃、服務(wù)器托管、小程序開發(fā)、動(dòng)態(tài)網(wǎng)站、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)