使用Sphinx和PHP通过部分字符串搜索结果

时间:2015-05-19 11:36:20

标签: php full-text-search sphinx

我试着开始使用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 = 5title = 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 );

但我不知道是不是很好。有人可以帮我理解我做错了什么吗?谢谢!

2 个答案:

答案 0 :(得分:3)

要获得'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

(但更好的是重写代码以避免调用折旧方法)

答案 1 :(得分:1)

警告setmatchmode

不推荐使用SetMatchMode,您仍然可以使用它,但可以在下一版本中将其删除。

有关它的更多信息:

从狮身人面像论坛(barryhunter)中提取:

  

更改'匹配模式'实际上做了两件事,它改变了匹配的>行为 -   重写查询本身。并改变排名模式。

     

通过解耦这些概念,我想这个想法可以减少混淆。

     

(例如,只要您选择其他匹配模式,就无法选择   排名模式)

     

...匹配模式是在“扩展语法”之前发生的。完全发展,但现在   一切都可以通过扩展语法直接完成。

关于搜索结果

barryhunter回答是对的

我建议阅读有关字符集表,形态和词干的更多信息,因为我认为这是一种比wilcard搜索更好的成功搜索方式。