Sphinx是由俄羅斯人Andrew Aksyonoff開發的一個全文檢索引擎。意圖為其他應用程式提供高速、低空間佔用、高結果 相關度的全文搜尋功能。 Sphinx可以非常容易的與SQL資料庫和腳本語言整合。目前系統內建MySQL和PostgreSQL 資料庫資料來源的支持,也支援從標準輸入讀取特定格式 的XML資料。
Sphinx的特性如下:
a) 高速的建立索引(在當代CPU上,峰值效能可達到10 MB/秒);
b) 高效能的搜尋(在2 – 4GB 的文字資料上,平均每次檢索回應時間小於0.1秒);
c) 可處理海量資料(目前已知可以處理超過100 GB的文字資料, 在單一CPU的系統上可處理100 M 文件);
d ) 提供了優秀的相關度演算法,基於短語相似度和統計(BM25)的複合Ranking方法;
e) 支持分散式搜尋;
f) 支援片語搜尋
g) 提供文件摘要產生
) 可作為MySQL的儲存引擎提供搜尋服務;i) 支援布林、片語、字詞相似度等多種擷取模式;j) 文件支援多個全文擷取欄位(最大不超過32個); k) 文件支援多個額外的屬性資訊(例如:分組信息,時間戳等);l) 支持斷詞;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
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
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 }
/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
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