forked from FriendsOfSymfony/FOSElasticaBundle
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug fix: no Feature addition: yes Backwards compatibility break: no Encapsulated Pagerfanta dependency for pagination and added support for knp pagination component
- Loading branch information
Showing
13 changed files
with
306 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace FOQ\ElasticaBundle\Paginator; | ||
|
||
use Pagerfanta\Adapter\AdapterInterface; | ||
use FOQ\ElasticaBundle\Paginator\PaginatorAdapterInterface; | ||
|
||
class FantaPaginatorAdapter implements AdapterInterface | ||
{ | ||
private $adapter; | ||
|
||
/** | ||
* @param PaginatorAdapterInterface $adapter | ||
*/ | ||
public function __construct(PaginatorAdapterInterface $adapter) | ||
{ | ||
$this->adapter = $adapter; | ||
} | ||
|
||
/** | ||
* Returns the number of results. | ||
* | ||
* @return integer The number of results. | ||
* | ||
* @api | ||
*/ | ||
public function getNbResults() | ||
{ | ||
return $this->adapter->getTotalHits(); | ||
} | ||
|
||
/** | ||
* Returns an slice of the results. | ||
* | ||
* @param integer $offset The offset. | ||
* @param integer $length The length. | ||
* | ||
* @return array|\Traversable The slice. | ||
* | ||
* @api | ||
*/ | ||
public function getSlice($offset, $length) | ||
{ | ||
return $this->adapter->getResults($offset,$length)->toArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace FOQ\ElasticaBundle\Paginator; | ||
|
||
interface PaginatorAdapterInterface | ||
{ | ||
/** | ||
* Returns the number of results. | ||
* | ||
* @return integer The number of results. | ||
* | ||
* @api | ||
*/ | ||
function getTotalHits(); | ||
|
||
/** | ||
* Returns an slice of the results. | ||
* | ||
* @param integer $offset The offset. | ||
* @param integer $length The length. | ||
* | ||
* @return FOQ\ElasticaBundle\Paginator\PartialResults | ||
* | ||
* @api | ||
*/ | ||
function getResults($offset, $length); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace FOQ\ElasticaBundle\Paginator; | ||
|
||
interface PartialResultsInterface | ||
{ | ||
/** | ||
* Returns the paginated results. | ||
* | ||
* @return array | ||
* | ||
* @api | ||
*/ | ||
function toArray(); | ||
|
||
/** | ||
* Returns the number of results. | ||
* | ||
* @return integer The number of results. | ||
* | ||
* @api | ||
*/ | ||
function getTotalHits(); | ||
|
||
|
||
/** | ||
* Returns the facets | ||
* | ||
* @return array | ||
*/ | ||
function getFacets(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace FOQ\ElasticaBundle\Paginator; | ||
|
||
use FOQ\ElasticaBundle\Paginator\PartialResultsInterface; | ||
use Elastica_ResultSet; | ||
|
||
/** | ||
* Raw partial results transforms to a simple array | ||
*/ | ||
class RawPartialResults implements PartialResultsInterface | ||
{ | ||
protected $resultSet; | ||
|
||
/** | ||
* @param \Elastica_ResultSet $resultSet | ||
*/ | ||
public function __construct(Elastica_ResultSet $resultSet) | ||
{ | ||
$this->resultSet = $resultSet; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function toArray() | ||
{ | ||
return array_map(function($result) { | ||
return $result->getSource(); | ||
}, $this->resultSet->getResults()); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getTotalHits() | ||
{ | ||
return $this->resultSet->getTotalHits(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getFacets() | ||
{ | ||
if ($this->resultSet->hasFacets()) { | ||
return $this->resultSet->getFacets(); | ||
} | ||
|
||
return null; | ||
} | ||
} |
Oops, something went wrong.