我正在尝试使用 Sphinx 搜索具有不同字段的几个 MySQL 表,并根据相关性将所有结果组合成一个集合。
我已经为 Sphinx 配置了每个表的索引,并通过一次搜索所有索引成功地组合了结果。
当我SEARCH
通过 shell 查询时,我按预期返回了所有结果信息。但是,当我使用 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 是搜索
输出如下所示的内容:
Sphinx 2.0.3-release (r3043) 版权所有 (c) 2001-2011, Andrew Aksyonoff 版权所有 (c) 2008-2011, Sphinx Technologies Inc (http://sphinxsearch.com)
使用配置文件“/usr/local/sphinx/etc/sphinx.conf”...索引“用户”:查询“NEWTON”:在 0.000 秒内返回 10 个匹配项,共 10 个
显示匹配项: 1. document=1,weight=2629,time=Thu Jan 1 00:33:32 1970 id=1 first_name=Joe last_name=Shmo company=Acme
JSON 格式的 PHP API 输出: { "error":"", "warning":"", "status":"good", "fields": ["name","code_name","code","description ","rating","angles","published","key_words","referenced_num","approved","used_num","avg_runtime","examples","editor","published_time"], "attrs" :{"time":2}, "matches": [ {"id":1,"weight":"1","attrs":{"time":2012}} ], "total":"1" , "total_found":"1", "time":"0.000", "words":{"posuere":{"docs":"1","hits":"2"}} }