diff --git a/README.md b/README.md index b52f4941..6f86ab10 100644 --- a/README.md +++ b/README.md @@ -315,6 +315,22 @@ $query->setQuery('search term'); $adapter = new SolariumAdapter($solarium, $query); ``` +### SphinxAdapter +To paginate a [Sphinx](http://sphinxsearch.com/) query: + +```php +client = $client; + $this->query = $query; + $this->index = $index; + $this->comment = $comment; + } + + /** + * {@inheritdoc} + */ + public function getNbResults() + { + if (!$this->results) { + return $this->client->query($this->query, $this->index, $this->comment)['total']; + } + + return $this->results['total']; + } + + /* + * setMaxMatches + * + * @param int $maxMatches Controls how much matches searchd will keep in RAM while searching. + * + * @return SphinxAdapter + */ + public function setMaxMatches($maxMatches) + { + $this->maxMatches = $maxMatches; + + return $this; + } + + /* + * getMaxMatches + * + * @param void + * + * @return int + */ + public function getMaxMatches() + { + return $this->maxMatches; + } + + /* + * setCutoff + * + * @param $cutoff Used for advanced performance control. It tells searchd to forcibly stop search query once cutoff matches have been found and processed. + * + * @return SphinxAdapter + */ + public function setCutoff($cutoff) + { + $this->cutoff = $cutoff; + + return $this; + } + + /* + * getCutoff + * + * @param void + * + * @return int + */ + public function getCutoff() + { + return $this->cutoff; + } + + /** + * {@inheritdoc} + */ + public function getSlice($offset, $limit) + { + // Set limit + $this->client->setLimits($offset, $limit, $this->maxMatches, $this->cutoff); + + return $this->results = $this->client + ->query($this->query, $this->index, $this->comment); + } +} \ No newline at end of file