2011-04-15 01:23:10 +02:00
|
|
|
<?php
|
|
|
|
|
2013-03-27 18:44:06 +01:00
|
|
|
namespace FOS\ElasticaBundle\Paginator;
|
2011-04-15 01:23:10 +02:00
|
|
|
|
2013-03-27 18:44:06 +01:00
|
|
|
use FOS\ElasticaBundle\Transformer\ElasticaToModelTransformerInterface;
|
2013-04-22 13:20:10 +02:00
|
|
|
use Elastica\SearchableInterface;
|
|
|
|
use Elastica\Query;
|
2011-04-15 01:23:10 +02:00
|
|
|
|
|
|
|
/**
|
2013-04-22 13:20:10 +02:00
|
|
|
* Allows pagination of \Elastica\Query
|
2011-04-15 01:23:10 +02:00
|
|
|
*/
|
2012-05-22 15:23:51 +02:00
|
|
|
class TransformedPaginatorAdapter extends RawPaginatorAdapter
|
2011-04-15 01:23:10 +02:00
|
|
|
{
|
2012-05-22 15:23:51 +02:00
|
|
|
private $transformer;
|
2011-04-15 01:23:10 +02:00
|
|
|
|
|
|
|
/**
|
2013-04-22 13:20:10 +02:00
|
|
|
* @param SearchableInterface $searchable the object to search in
|
|
|
|
* @param Query $query the query to search
|
2013-03-02 12:23:44 +01:00
|
|
|
* @param ElasticaToModelTransformerInterface $transformer the transformer for fetching the results
|
2011-04-15 01:23:10 +02:00
|
|
|
*/
|
2014-02-05 02:41:38 +01:00
|
|
|
public function __construct(SearchableInterface $searchable, Query $query, array $options = array(), ElasticaToModelTransformerInterface $transformer)
|
2011-04-15 01:23:10 +02:00
|
|
|
{
|
2014-02-05 02:41:38 +01:00
|
|
|
parent::__construct($searchable, $query, $options);
|
2011-04-27 09:59:04 +02:00
|
|
|
|
|
|
|
$this->transformer = $transformer;
|
2011-04-15 01:23:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-05-22 15:23:51 +02:00
|
|
|
* {@inheritDoc}
|
2011-04-15 01:23:10 +02:00
|
|
|
*/
|
2012-05-22 15:23:51 +02:00
|
|
|
public function getResults($offset, $length)
|
2011-04-15 01:23:10 +02:00
|
|
|
{
|
2012-06-13 20:28:16 +02:00
|
|
|
return new TransformedPartialResults($this->getElasticaResults($offset, $length), $this->transformer);
|
2011-04-15 01:23:10 +02:00
|
|
|
}
|
|
|
|
}
|