【问题标题】:Searching through multiple fields in SphinxSearch (PHP)在 SphinxSearch (PHP) 中搜索多个字段
【发布时间】:2013-08-15 01:57:08
【问题描述】:

我有以下代码:

$this->api = new App_Other_SphinxSearch();
$this->api->SetServer($host, $port);
$this->api->SetConnectTimeout(1);
$this->api->SetArrayResult(true);
$results = $this->api->Query("@(title,content) test", 'members');

echo "<pre>";print_r($results);die;

根据their documentation,像@(field_1,field_2) query 这样的语法应该返回与field_1field_2 中的字符串query 匹配的文档。

PHP SDK 返回完全不同的东西:

Array
(
    [error] => 
    [warning] => 
    [status] => 0
    [fields] => Array
        (
            [0] => title
            [1] => content
        )

    [attrs] => Array
        (
            [created] => 2
            [content] => 7
        )

    [total] => 0
    [total_found] => 0
    [time] => 0.000
    [words] => Array
        (
            [title] => Array
                (
                    [docs] => 10
                    [hits] => 34
                )

            [content] => Array
                (
                    [docs] => 34
                    [hits] => 139
                )

            [test] => Array
                (
                    [docs] => 26
                    [hits] => 34
                )

        )

)

数组中没有matches 键,但是它得到了一些命中。我真的不明白为什么会发生这种情况,特别是因为如果我从命令行尝试相同的查询,一切正常。

有什么帮助吗?

编辑: 像这样的查询虽然有效:@* test。不过,这并不是我真正想要的,因为它会在所有领域进行搜索。

【问题讨论】:

    标签: php indexing sphinx


    【解决方案1】:

    [total_found] =&gt; 0 说那里有 no 匹配。

    words 数组,只是告诉你现在有多少个文档,以及这个词在任何(和所有)字段中出现的次数。 (不考虑您的具体查询)

    Sphinx 会缓存这些单词的统计信息,这有助于它对查询进行快速的健全性检查。当查询运行时,它最终可能不匹配任何文档(因为只有这样它才会应用字段级过滤器),即使找到了单个单词。


    这解释了您对结果的误解,但不能解释为什么要获得结果。

    您正在输入扩展模式查询(如 sphinx 文档的链接所示),但 sphinx API 默认为 ALL 查询模式。另请注意,标题和内容在 words 数组中,因此被视为普通关键字而不是语法。

    所以你需要包含一个

    $this->api->SetMatchMode(SPH_MATCH_EXTENDED);
    

    顺便说一句,@* test 之所以有效,是因为 @* 在所有查询模式下都被忽略了。

    【讨论】:

    • 给你一句话,我的朋友:救生员 :) Notice also that title and content are in the words array, so are being taken as plain keywords not as syntax. -- 我只是在发布我的问题后才发现这一点,但不知道如何解决它。现在一切正常。谢谢!
    猜你喜欢
    • 2014-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-18
    相关资源
    最近更新 更多