sphinx使用步驟:
1、安裝
windows
直接解壓就可以了
linux
源碼安裝
2、配置
SQL 結構化查詢語言 MYSQL數據庫 oracle數據庫 sqlserver數據庫 但是這三個數據庫都要遵循SQL規則
理解配置文件的結構
source ecshop{
}
index mygoods{
}
source ecshop1{
}
index mygoods1{
source = ecshop1 指定索引用戶哪個數據源
}
indexer{
mem_limit = 128M
}
searchd{
}
注意:
1、數據庫配置和索引配置必須成對出現可以有多個
2、sql_query_pre 這個參數可以多個,主要是在執行主查詢之前進行的操作
3、sql_query 這個主查詢,主要從MYSQL數據庫中拿到要建立索引的數據,
sql_query = select 必須是主鍵,搜索的字段名,搜索的字段名 from 表名
4、sql_attr_uint 設置屬性 ,可以多個,屬性字段必須在主查詢時查詢出來
[matches] => Array
(
[29] => Array
(
[weight] => 1
[attrs] => Array
(
[cat_id] => 14 設置屬性
)
)
[30] => Array
(
[weight] => 1
[attrs] => Array
(
[cat_id] => 14
)
)
)
3、生成索引
Indexer.exe -c 配置文件 參數(--all 表示所有的索引 | 索引名稱)
indexer.exe -c .\etc\csft_mysql.conf --all
indexer.exe -c .\etc\csft_mysql.conf mygoods(索引名稱)
4、開啓searchd服務 端口號默認是9312
searchd.exe -c .\etc\csft_mysql.conf
注意:
如果開啓服務後,再次重新建立索引,需要重啓服務
5、引入sphinxapi接口或者安裝sphinx擴展
6、進行實例化對象,查詢數據
require "sphinxapi.php";
$sphinxapi = new SphinxClient();
$sphinxapi->SetServer('127.0.0.1', 9312);
$result = $sphinxapi->Query('移動', 'mygoods');
print_r($result);