【发布时间】:2012-04-18 23:18:17
【问题描述】:
我正在尝试使用 Sphinx 搜索具有不同字段的多个 MySQL 表,并根据相关性将所有结果组合成一个集合。
我已为 Sphinx 配置了每个表的索引,并通过一次搜索所有索引成功地组合了结果。
当我通过 shell 使用 SEARCH 进行查询时,我按预期返回了所有结果信息。但是,当我使用 PHP API 时,返回的结果只包含行的 ID,因此无法判断它来自哪个表。
有没有办法让 PHP API 告诉我它来自哪个表/索引,以便我可以进入并查询实际数据?
我正在考虑的替代方法是尝试处理 shell 脚本的输出,但这看起来很混乱。
这里是 PHP: $search = $_GET['查询']; // 连接信息 $sphinxClient = 新的 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 版本 (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.文档=1,权重=2629,时间=Thu Jan 1 00:33:32 1970 id=1 first_name=乔 姓氏=Shmo 公司=Acme
JSON 格式的 PHP API 输出: { “错误”:””, “警告”:””, “状态”:“好”, "fields": ["name","code_name","code","description","rating","angles","published","key_words","referenced_num","approved","used_num"," avg_runtime","examples","editor","published_time"], “属性”:{“时间”:2}, “火柴”: [ {"id":1,"weight":"1","attrs":{"time":2012}} ], “总计”:“1”, "total_found":"1", “时间”:“0.000”, “单词”:{“posuere”:{“文档”:“1”,“点击”:“2”}} }
【问题讨论】:
-
请在您执行 PHP API 搜索的位置添加代码,以便更清楚您如何执行此操作。接下来,请记录您所做的 shell 命令行,以便相互比较。
-
./search shell 脚本不是为生产使用而开发的。它是调试和监控索引状态和内容的工具。您应该改用 Sphinx API。