使用 Sphinx 和 PHP 按部分字符串搜索结果
Search results with Sphinx and PHP by partial string
我正在尝试开始使用 Sphinx。我将一些结果添加到索引,下载 sphinxapi.php
,当我这样做时:
$cl = new SphinxClient();
$cl->SetServer( "localhost", 9312 );
// SPH_MATCH_ALL will match all words in the search term
$cl->SetMatchMode(SPH_MATCH_ALL);
$result = $cl->Query("test");
我得到这个(id = 5
行,其中 title = test
):
array (size=1)
5 => // id of post in database
array (size=2)
'weight' => string '2' (length=1)
'attrs' =>
array (size=0)
empty
但是为什么我没有从 id = 6
的数据库中获取行,其中 title
字段等于 test1
?
并且$cl->SetMatchMode(SPH_MATCH_ALL);
触发错误:
DEPRECATED: Do not call this method or, even better, use SphinxQL instead of an API
我在 api 文件的代码中注释了这一行:
trigger_error ( 'DEPRECATED: Do not call this method or, even better, use SphinxQL instead of an API', E_USER_DEPRECATED );
但是不知道好不好。有人可以帮助我了解我做错了什么吗?谢谢!
要获得 'substring' 个匹配项,您需要专门启用它们。
http://sphinxsearch.com/docs/current.html#conf-min-prefix-len
(或min_infix_len)
如果你不想看到折旧通知,那么设置error_reporting
http://php.net/manual/en/function.error-reporting.php
(但更好的是重写代码以避免调用折旧方法)
警告设置匹配模式
SetMatchMode 已弃用,您仍然可以使用它,但可以在下一版本中将其删除。
有关它的更多信息:
- http://sphinxsearch.com/docs/current.html#api-func-setmatchmode
- http://sphinxsearch.com/blog/2013/09/11/deprecations-and-changes-in-the-2-2-series/
摘自 sphinx 论坛 (barryhunter):
Changing the 'match mode' actually did TWO things, it changed the matching >behaviour - by
rewriting the query itself. AND changing the ranking mode.
By decoupling these concepts, I guess the idea is reduce confusion.
(for example, as soon as you choose a different matching mode, you can't >actully choose a
ranking mode)
... the match modes made sence before the 'extended syntax' was fully developed, but now
everything can be done directly via the extended syntax.
关于搜索结果
barryhunter 回答正确
我建议阅读更多关于字符集表、形态学和词干提取的内容,因为我认为这是比通配符搜索更好的实现成功搜索的方法。
我正在尝试开始使用 Sphinx。我将一些结果添加到索引,下载 sphinxapi.php
,当我这样做时:
$cl = new SphinxClient();
$cl->SetServer( "localhost", 9312 );
// SPH_MATCH_ALL will match all words in the search term
$cl->SetMatchMode(SPH_MATCH_ALL);
$result = $cl->Query("test");
我得到这个(id = 5
行,其中 title = test
):
array (size=1)
5 => // id of post in database
array (size=2)
'weight' => string '2' (length=1)
'attrs' =>
array (size=0)
empty
但是为什么我没有从 id = 6
的数据库中获取行,其中 title
字段等于 test1
?
并且$cl->SetMatchMode(SPH_MATCH_ALL);
触发错误:
DEPRECATED: Do not call this method or, even better, use SphinxQL instead of an API
我在 api 文件的代码中注释了这一行:
trigger_error ( 'DEPRECATED: Do not call this method or, even better, use SphinxQL instead of an API', E_USER_DEPRECATED );
但是不知道好不好。有人可以帮助我了解我做错了什么吗?谢谢!
要获得 'substring' 个匹配项,您需要专门启用它们。
http://sphinxsearch.com/docs/current.html#conf-min-prefix-len
(或min_infix_len)
如果你不想看到折旧通知,那么设置error_reporting http://php.net/manual/en/function.error-reporting.php
(但更好的是重写代码以避免调用折旧方法)
警告设置匹配模式
SetMatchMode 已弃用,您仍然可以使用它,但可以在下一版本中将其删除。
有关它的更多信息:
- http://sphinxsearch.com/docs/current.html#api-func-setmatchmode
- http://sphinxsearch.com/blog/2013/09/11/deprecations-and-changes-in-the-2-2-series/
摘自 sphinx 论坛 (barryhunter):
Changing the 'match mode' actually did TWO things, it changed the matching >behaviour - by rewriting the query itself. AND changing the ranking mode.
By decoupling these concepts, I guess the idea is reduce confusion.
(for example, as soon as you choose a different matching mode, you can't >actully choose a ranking mode)
... the match modes made sence before the 'extended syntax' was fully developed, but now everything can be done directly via the extended syntax.
关于搜索结果
barryhunter 回答正确
我建议阅读更多关于字符集表、形态学和词干提取的内容,因为我认为这是比通配符搜索更好的实现成功搜索的方法。