天天看點

sphinx全文檢索引擎sphinx站内搜尋mysql 索引

sphinx站内搜尋

基于SQL的全文檢索引擎

mysql 索引

# 加索引
mysql> alter table <table_name> add index <index_name>(<field_name>);

# 加主關鍵字的索引
mysql> alter table <table_name> add primary key (<field_name>);
      

1、站内搜尋

2、背景搜尋

PHP -> MySQL

PHP -> Sphinx <-> MySQL

優勢

mysql直接查詢較慢

中文分詞

速度快

-高速建立索引 10M/s

-高性能搜尋 2-4G 0.1s

-海量資料

安裝

http://sphinxsearch.com/

$ whereis sphinxsearsh

兩個重要的工具

indexer:用于建立索引

searched:用于背景

配置

/etc/sphinxsearch/sphinx.conf

工作原理

indexer —> index data <— searched <— service/web

生成索引資料

/usr/bin/indexer --config /etc/sphinxsearch/sphinx.conf --all

索引檔案存儲的資料種類

.spa 存儲文檔屬性

.spd 存儲每個詞ID可比對的文檔ID清單

.sph 存儲索引頭資訊

.spi 存儲詞清單

.spm 存儲MVA資料

.spp 存儲每個詞的命中清單

檢視程序

ps -axu |grep searched

檢視sphinx資料

mysql -h0 -p9306

select * from <index_name> limit 10;