似乎Sphinx正在逐字搜索文档.我不知道如何在文档中搜索确切的短语.我尝试了SPH_MATCH_ALL,SPH_MATCH_PHRASE,但都是逐字搜索文档.我在我的
PHP应用程序中使用它.
原文链接:https://www.f2er.com/php/133205.html如何查询Sphinx以匹配精确的字符串?
这是我的代码:
$sphinx = new SphinxClient(); $mode = SPH_MATCH_PHRASE; $sphinx->setServer('127.0.0.1',9312); $sphinx->setLimits(0,1); $sphinx->setMaxQueryTime(5000); $sphinx->setMatchMode($mode); $sphinx->setFieldWeights(array('name' => 100)); $sphinx->setArrayResult(true); $result = $sphinx->query('Lorem ipsum dolor sit amet,consectetur adipiscing elit.'); print_r($result);
返回结果如下:
Array ( [error] => [warning] => [status] => 0 [fields] => Array ( [0] => name [1] => company [2] => image [3] => price ) [attrs] => Array () [total] => 0 [total_found] => 0 [time] => 0.000 [words] => Array ( [lorem] => Array ( [docs] => 0 [hits] => 0 ) [ipsum] => Array ( [docs] => 0 [hits] => 0 ) [dolor] => Array ( [docs] => 0 [hits] => 0 ) [sit] => Array ( [docs] => 0 [hits] => 0 ) [amet] => Array ( [docs] => 0 [hits] => 0 ) [consectetur] => Array ( [docs] => 0 [hits] => 0 ) [adipiscing] => Array ( [docs] => 0 [hits] => 0 ) [elit] => Array ( [docs] => 0 [hits] => 0 ) ) )