FOSElasticaBundle/Paginator/RawPartialResults.php

65 lines
1.2 KiB
PHP
Raw Permalink Normal View History

<?php
namespace FOS\ElasticaBundle\Paginator;
use Elastica\ResultSet;
use Elastica\Result;
/**
2015-03-12 11:20:00 +01:00
* Raw partial results transforms to a simple array.
*/
class RawPartialResults implements PartialResultsInterface
{
protected $resultSet;
/**
* @param ResultSet $resultSet
*/
public function __construct(ResultSet $resultSet)
{
$this->resultSet = $resultSet;
}
/**
* {@inheritDoc}
*/
public function toArray()
{
2015-03-12 11:20:00 +01:00
return array_map(function (Result $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();
}
2015-03-12 11:20:00 +01:00
return;
}
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
}
}