PHP Velho Oeste 2024

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
14 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
8 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
14 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
15 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
To Top