Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,22 @@ $query->setQuery('search term');
$adapter = new SolariumAdapter($solarium, $query);
```

### SphinxAdapter
To paginate a [Sphinx](http://php.net/manual/en/class.sphinxclient.php) query:

Copy link
Copy Markdown
Collaborator

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/?


```php
<?php

use Pagerfanta\Adapter\SphinxAdapter;

$query = '*';
$index = 'example_index';
$comment = '';

$sphinxClient = new SphinxClient();
$adapter = new SphinxAdapter($sphinxClient, $query, $index, $comment);
```

### FixedAdapter

Best used when you need to do a custom paging solution and
Expand Down
84 changes: 84 additions & 0 deletions src/Pagerfanta/Adapter/SphinxAdapter.php
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>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you missing a setter for $maxMatches?

private $cutoff = 0;

/**
* Constructor.
*
* @param SphinxClient $client A Sphinx client.
* @param $query A Sphinx query.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are @query, $index and $comment all strings? Please could you update the docblock to show this?

* @param $index A Sphinx index.
* @param $comment A Sphinx comment.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you tidy the indentation here too, please?

}

/**

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please could you put a variable type in this docblock too?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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);
}
}