2012-05-22 15:23:51 +02:00
|
|
|
<?php
|
|
|
|
|
2013-03-27 18:44:06 +01:00
|
|
|
namespace FOS\ElasticaBundle\Paginator;
|
2012-05-22 15:23:51 +02:00
|
|
|
|
2013-04-22 13:20:10 +02:00
|
|
|
use Elastica\ResultSet;
|
|
|
|
use Elastica\Result;
|
2012-05-22 15:23:51 +02:00
|
|
|
|
|
|
|
/**
|
2015-03-12 11:20:00 +01:00
|
|
|
* Raw partial results transforms to a simple array.
|
2012-05-22 15:23:51 +02:00
|
|
|
*/
|
|
|
|
class RawPartialResults implements PartialResultsInterface
|
|
|
|
{
|
|
|
|
protected $resultSet;
|
|
|
|
|
|
|
|
/**
|
2013-04-22 13:20:10 +02:00
|
|
|
* @param ResultSet $resultSet
|
2012-05-22 15:23:51 +02:00
|
|
|
*/
|
2013-04-22 13:20:10 +02:00
|
|
|
public function __construct(ResultSet $resultSet)
|
2012-05-22 15:23:51 +02:00
|
|
|
{
|
|
|
|
$this->resultSet = $resultSet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function toArray()
|
|
|
|
{
|
2015-03-12 11:20:00 +01:00
|
|
|
return array_map(function (Result $result) {
|
2012-05-22 15:23:51 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2015-03-12 11:20:00 +01:00
|
|
|
return;
|
2012-05-22 15:23:51 +02:00
|
|
|
}
|
2015-03-12 11:57:26 +01:00
|
|
|
|
2014-10-08 19:27:50 +02:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function getAggregations()
|
|
|
|
{
|
|
|
|
if ($this->resultSet->hasAggregations()) {
|
|
|
|
return $this->resultSet->getAggregations();
|
|
|
|
}
|
|
|
|
|
2015-03-12 11:57:26 +01:00
|
|
|
return;
|
2014-10-08 19:27:50 +02:00
|
|
|
}
|
|
|
|
}
|