【问题标题】:How to do this with Sphinx (limit search results number)如何使用 Sphinx 执行此操作(限制搜索结果数量)
【发布时间】:2011-08-20 12:17:24
【问题描述】:

我是 Sphinx 的新手,需要一些帮助。我正在使用 PHP 脚本查询 Sphinx 服务器,例如:

 $cl = new SphinxClient();
 $cl->SetServer( "host", 9312 );
 $cl->SetMatchMode( SPH_MATCH_ANY  );
 $result = $cl->Query( "some word",  "index1" );  

现在我想知道如何提取 SAME 查询的前 20 个结果,然后是接下来的 20 个结果,等等,例如在 MySQL LIMIT 0,20,然后是 LIMIT 20,20 等?

【问题讨论】:

    标签: php sphinx


    【解决方案1】:
    $offset = 0;
    if (isset($_GET['offset'])) {
        $offset = $_GET['offset'];
    }
    $limit = 30;
    $max_matches = 1000;
    $cl = new SphinxClient();
    
    $cl->SetLimits((int)$offset,
        // limit for this "page", starting at $offset
        (int)$limit,
        // absolute limit for number of results
        ((int)$limit > $max_matches)
            ? (int)$limit
            : (int)$max_matches);
    

    其中$offset 是当前开始记录(默认为 0),$limit 是每页显示的记录数,$max_matches 是您希望允许在单个搜索中返回的最大匹配数。

    【讨论】:

      【解决方案2】:
      【解决方案3】:
      【解决方案4】:

      第一次

      $cl->SetLimits(0,20);
      

      然后

      $cl->SetLimits(20,20);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-04-12
        • 2013-03-27
        • 2012-09-24
        • 1970-01-01
        • 2015-03-30
        • 2014-02-17
        • 2017-04-15
        • 2016-10-02
        相关资源
        最近更新 更多