我正在嘗試使用Sphinx搜索不同字段的多個MySQL表,並將所有結果組合到基於相關性的單個集合中。Sphinx使用PHP API搜索多個表和聚合結果
我已經爲每個表配置了Sphinx索引,並且通過一次搜索所有索引成功組合了結果。
當我通過shell使用SEARCH
來查詢時,我得到了所有的結果信息。但是,當我使用PHP API時,結果只會返回行的ID,因此無法分辨它來自哪個表。
有沒有辦法讓PHP API告訴我它來自哪個表/索引,以便我可以進入並查詢實際數據?
我正在考慮的替代方法是嘗試處理來自shell腳本的輸出,但似乎很混亂。
這是PHP: $ search = $ _GET ['query']; //連接信息 $ sphinxClient = new SphinxClient(); $ sphinxClient-> SetServer('localhost',9312); $ sphinxClient-> SetMaxQueryTime(5000);
//Sphinx Result Configuration
$sphinxClient->SetMatchMode(SPH_MATCH_ANY);
$sphinxClient->SetRankingMode(SPH_RANK_PROXIMITY_BM25);
$sphinxClient->SetLimits(0, 20);
// Give me back the results as an array
$sphinxClient->SetArrayResult(true);
$searchResults = $sphinxClient->Query($search, 'user model');
shell腳本很簡單:
./search SEARCHTERM
其中SEARCHTERM是輸出的東西看起來搜索
,如:
獅身人面像2.0.3 - 釋放(r3043) Copyright(c)2001-2011,Andrew Aksyonoff Sphinx Technologies Inc(http://sphinxsearch.com)版權所有(c)2008-2011
使用配置文件'/ usr/local/sphinx/etc/sphinx的.conf '... 索引 '用戶':查詢' 牛頓的「:返回10總在0.000秒
顯示比賽的10個匹配: 1.文檔= 1,權重= 2629,時間=星期四00年1月1日:33:32 1970 ID = 1 如first_name =喬 姓氏= Shmo 公司= Acme公司
JSON格式的PHP API輸出: { 「錯誤」: 「」, 「警告」: 「」, 「狀態」: 「好」, 「田」: 「名字」, 「CODE_NAME」 「代碼」, 「說明」, 「等級」, 「角度」, 「發佈」, 「key_words」, 「referenced_num」, 「批准」, 「used_num」, 「avg_runtime」, 「例子」, 「編輯」,」 attrs「:{」time「:2}, 」matches「: [ {」id「:1,」weight「:」1「,」attrs「:{」time「 }} ], 「total」:「1」, 「total_found」:「1」, 「time」:「0。000「, 」words「:{」posuere「:{」docs「:」1「,」hits「:」2「}} }
請添加在您執行PHP API搜索代碼,以便它的更清楚你如何做到這一點。接下來,請記錄您所做的shell命令行,以便可以相互比較。 – hakre 2012-04-05 08:10:17
./search搜索shell腳本不是爲生產使用而開發的。它是調試和監視索引狀態和內容的工具。您應該使用Sphinx API。 – 2012-04-05 11:22:13