-
Notifications
You must be signed in to change notification settings - Fork 2
Implemented SphinxAdapter #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 5 commits
eeef0cb
582589c
ebdbeda
6613d83
b33308a
fa816e5
e22167e
afc43c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| <?php | ||
| /* | ||
| * This file is part of the Pagerfanta package. | ||
| * | ||
| * (c) Maikel Doezé <maikel.doeze@marqin.nl> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you remove the copyright message? I know that many of the files have a copyright message relating to Pablo Diez, but for simplicity, we want to move towards one copyright framework for the whole project rather than per-file statements. |
||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Pagerfanta\Adapter; | ||
|
|
||
| use SphinxClient; | ||
|
|
||
| class SphinxAdapter implements AdapterInterface | ||
| { | ||
| private $client; | ||
| private $query; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need the extra indent here. |
||
| private $index; | ||
| private $comment; | ||
| private $results; | ||
| private $maxMatches = 0; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you missing a setter for |
||
| private $cutoff = 0; | ||
|
|
||
| /** | ||
| * Constructor. | ||
| * | ||
| * @param SphinxClient $client A Sphinx client. | ||
| * @param $query A Sphinx query. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are |
||
| * @param $index A Sphinx index. | ||
| * @param $comment A Sphinx comment. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please could you fix the indentation on these two lines? |
||
| */ | ||
| public function __construct(SphinxClient $client, $query, $index = "*", $comment = "") | ||
| { | ||
| $this->client = $client; | ||
| $this->query = $query; | ||
| $this->index = $index; | ||
| $this->comment = $comment; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you tidy the indentation here too, please? |
||
| } | ||
|
|
||
| /** | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You've got a bit of extra indentation here that you don't need. |
||
| * {@inheritdoc} | ||
| */ | ||
| public function getNbResults() | ||
| { | ||
| if (!$this->results) { | ||
| return $this->client->query($this->query, $this->index, $this->comment)['total']; | ||
| } | ||
|
|
||
| return $this->results['total']; | ||
| } | ||
|
|
||
| /* | ||
| * setMaxMatches | ||
| * | ||
| * @param $maxMatches Controls how much matches searchd will keep in RAM while searching. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you put a variable type in the docblock here too please? |
||
| */ | ||
| public function setMaxMatches($maxMatches) | ||
| { | ||
| $this->maxMatches = $maxMatches; | ||
| } | ||
|
|
||
| /* | ||
| * setCutoff | ||
| * | ||
| * @param $maxMatches Used for advanced performance control. It tells searchd to forcibly stop search query once cutoff matches have been found and processed. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please could you put a variable type in this docblock too?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, the variable name in the docblock doesn't match the parameter name. |
||
| */ | ||
| public function setCutoff($cutoff) | ||
| { | ||
| $this->cutoff = $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); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a better page you could link to? The PHP client page doesn't actually say what Sphinx is. Is it http://sphinxsearch.com/?