How to do this with Sphinx (limit search results number)
I am new to Sphinx, and need some help. I am querying Sphinx server with PHP script like:
$cl = new SphinxClient();
$cl->SetServer( "host", 9312 );
$cl->SetMatchMode( SPH_MATCH_ANY );
$result = $cl->Query( "some word", "index1" );
Now I would like to know how to pull for SAME query first 20 results, then next 20 results, etc,开发者_JS百科 like in MySQL LIMIT 0,20
, then LIMIT 20,20
, etc?
$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);
Where $offset
is the current start record (default 0), $limit
is the number of records to display per page, and $max_matches
is the maximum number of matches you want allow returned in a single search.
$cl->SetLimits($ooset, $limit);
http://sphinxsearch.com/wiki/doku.php?id=php_api_docs#setlimits_offset_limit_max_cutoff
$cl->SetLimits($offset, $limit);
http://sphinxsearch.com/wiki/doku.php?id=php_api_docs#setlimits_offset_limit_max_cutoff
First time
$cl->SetLimits(0,20);
then
$cl->SetLimits(20,20);
精彩评论