略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: SphinxClient::setLimits

2024-12-23

SphinxClient::setLimits

(PECL sphinx >= 0.1.0)

SphinxClient::setLimits设置返回结果集偏移量和数目

说明

public SphinxClient::setLimits ( int $offset , int $limit [, int $max_matches = 0 [, int $cutoff = 0 ]] ) : bool

给服务器端结果集设置一个偏移量 offset 从那个偏移量起向客户端返回的匹配项数目限制(limit) . 并且可以在服务器端设定当前查询的结果集大小 (max_matches) ,另有一个阈值 (cutoff),当找到的匹配项达到这个阀值时就停止搜索。

参数

offset

结果集的偏移量.

limit

返回的匹配项数目.

max_matches

设置控制搜索过程中searchd在内存中所保持的匹配项数目.

cutoff

该设置是为高级性能优化而提供的. 它告诉searchd 在找到并处理 cutoff 个匹配后就强制停止.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

add a note add a note

User Contributed Notes 4 notes

up
1
xxxbunker dot com
9 years ago
the max_matches / cutoff parameters are priceless.

if you ever have a situation where you need a 'count' of the number of matches, but only need to display lets say the 'top 10', these 2 parameters are very handy.

we used to get the occasional 'unable to connect' error with sphinx, after implementing these 2 parameters where applicable, these issues disappeared, load dropped, and the servers were much happier.
up
0
vlk dot abakan at gmail dot com
3 years ago
If you use shpinxQL, you can add "max_matches" option to your query:

<?php
   SELECT
... LIMIT 1000, 10 OPTION max_matches = 1000
?>

And to "searchd" section in sphinx.conf:

<?php

searchd
{
    ...
   
max_matches = 10000
   
....
}

?>
up
0
shoanm at users dot sourceforge dot net
9 years ago
I almost pulled out all my hair trying to figure this one out. After applying limits using

$s->setLimit(10,10);

the search kept returning only false. getLastError() and getLastWarning() contained empty strings.

The solution, like Nayana stated, is to add a positive non-zero integer $max to setLimit.
up
0
Nayana Hettiarachch nayana at corp-gems dot com
10 years ago
If you get an error
per-query max_matches=0 out of bounds (per-server max_matches=1000).

make sure that you also set the $max to a value other than the default 0,

there is an issue published with a patch if you feel like wanting to patch,

the first option works well as a workaround.

http://sphinxsearch.com/bugs/view.php?id=208

官方地址:https://www.php.net/manual/en/sphinxclient.setlimits.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3