如何在Sphinx上查询完全匹配的词组?

Kev*_*Lee 8 php sphinx

似乎Sphinx正在逐字搜索文档.我不知道如何在文档中搜索确切的短语.我试过了SPH_MATCH_ALL,SPH_MATCH_PHRASE但所有人都是逐字搜索文件.我在我的PHP应用程序中使用它.

如何查询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);
Run Code Online (Sandbox Code Playgroud)

返回结果如下:

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
        )
    )
)
Run Code Online (Sandbox Code Playgroud)

如你所见,Sphinx正在逐字搜索文件......

Iar*_*hko 5

最好的方法是使用SPH_MATCH_EXTENDED2语法并使用双引号进行查询.

$sphinx->SetMatchMode(SPH_MATCH_EXTENDED2);
$sphinx->Query('"Lorem ipsum dolor"'); 
Run Code Online (Sandbox Code Playgroud)

扩展语法


Far*_*ona 3

使用:

$sphinx->SetMatchMode(SPH_MATCH_PHRASE);
Run Code Online (Sandbox Code Playgroud)

SPH_MATCH_ALL 匹配所有查询词(默认模式)。

SPH_MATCH_ANY 匹配任意查询词。

SPH_MATCH_PHRASE 将查询作为短语进行匹配,要求完美匹配。

SPH_MATCH_BOOLEAN 将查询作为布尔表达式进行匹配。

SPH_MATCH_EXTENDED 将查询匹配为 Sphinx 内部查询语言中的表达式。

SPH_MATCH_FULLSCAN 启用全扫描。

SPH_MATCH_EXTENDED2 与 SPH_MATCH_EXTENDED 相同,加上排名和仲裁搜索支持。