Sphinx\SphinxClient::setLimits PHP Method

setLimits() public method

Set offset and count into result set, optionally set max-matches and cutoff limits
public setLimits ( integer $offset, integer $limit, integer $max, integer $cutoff ) : SphinxClient
$offset integer
$limit integer
$max integer
$cutoff integer
return SphinxClient
    public function setLimits($offset, $limit, $max = 0, $cutoff = 0)
    {
        $offset = intval($offset);
        $limit = intval($limit);
        $max = intval($max);
        $cutoff = intval($cutoff);
        if ($offset < 0) {
            throw new \InvalidArgumentException('Offset cannot be negative.');
        }
        if ($limit <= 0) {
            throw new \InvalidArgumentException('Limit must be positive.');
        }
        if ($max < 0) {
            throw new \InvalidArgumentException('Maximum matches cannot be negative.');
        }
        if ($cutoff < 0) {
            throw new \InvalidArgumentException('Cutoff cannot be negative.');
        }
        $this->offset = $offset;
        $this->limit = $limit;
        if ($max) {
            $this->maxmatches = $max;
        }
        if ($cutoff) {
            $this->cutoff = $cutoff;
        }
        return $this;
    }

Usage Example

Example #1
0
 public function testSetLimits()
 {
     $sphinx = new SphinxClient();
     $sphinx->setLimits(100, 50, 2000, 5000);
     $this->assertSame($sphinx->offset, 100);
     $this->assertSame($sphinx->limit, 50);
     $this->assertSame($sphinx->maxmatches, 2000);
     $this->assertSame($sphinx->cutoff, 5000);
 }
All Usage Examples Of Sphinx\SphinxClient::setLimits