doubushi0031 2013-08-13 12:37
浏览 190
已采纳

在SphinxSearch(PHP)中搜索多个字段

I have the following code:

$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;

According to their documentation, a syntax like @(field_1,field_2) query should return docs which match the string query in either field_1 or field_2.

The PHP SDK returns something entirely different:

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
                )

        )

)

There is no matches key in the array, however it got some hits. I don't really understand why this is happening, especially because if I try the same query from the command line, everything works correctly.

Any help?

Edit: Querying like this works though: @* test. Not really what I want though, cause that searches in all fields.

  • 写回答

1条回答 默认 最新

  • douqian1975 2013-08-13 13:03
    关注

    [total_found] => 0 says there where no matches.

    The words array, just tells you now many documents and how many times that word appears in ANY (and all) fields. (WITHOUT regard to your specific query)

    Sphinx caches those word stats, which help it make quick sanity checks on queries. When the query runs it can end up not matching any documents (because only then does it apply the field level filters), even though the individual words are found.


    That explains your misinpretation of the results, but not why getting the results you get.

    You are entering a Extended Mode query (as evidenced by the link to the sphinx documentation) , but the sphinx API defaults to ALL query mode. Notice also that title and content are in the words array, so are being taken as plain keywords not as syntax.

    So you need to include a

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

    btw, @* test, works because the @* are simply ignored in ALL query mode.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab