Simon
Simon

Reputation: 121

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, like in MySQL LIMIT 0,20, then LIMIT 20,20, etc?

Upvotes: 0

Views: 5113

Answers (4)

Iaroslav Vorozhko
Iaroslav Vorozhko

Reputation: 1719

First time

$cl->SetLimits(0,20);

then

$cl->SetLimits(20,20);

Upvotes: 0

Glen Solsberry
Glen Solsberry

Reputation: 12320

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

Upvotes: 1

Related Questions