diff --git a/Paginator/FantaPaginatorAdapter.php b/Paginator/FantaPaginatorAdapter.php index 2ad6983..812afa8 100644 --- a/Paginator/FantaPaginatorAdapter.php +++ b/Paginator/FantaPaginatorAdapter.php @@ -39,6 +39,18 @@ class FantaPaginatorAdapter implements AdapterInterface { return $this->adapter->getFacets(); } + + /** + * Returns Aggregations + * + * @return mixed + * + * @api + */ + public function getAggregations() + { + return $this->adapter->getAggregations(); + } /** * Returns a slice of the results. diff --git a/Paginator/PaginatorAdapterInterface.php b/Paginator/PaginatorAdapterInterface.php index 25786a0..65271f0 100644 --- a/Paginator/PaginatorAdapterInterface.php +++ b/Paginator/PaginatorAdapterInterface.php @@ -31,4 +31,11 @@ interface PaginatorAdapterInterface * @return mixed */ function getFacets(); + + /** + * Returns Aggregations + * + * @return mixed + */ + function getAggregations(); } diff --git a/Paginator/PartialResultsInterface.php b/Paginator/PartialResultsInterface.php index 9efe7f3..1b0ae60 100644 --- a/Paginator/PartialResultsInterface.php +++ b/Paginator/PartialResultsInterface.php @@ -28,4 +28,11 @@ interface PartialResultsInterface * @return array */ function getFacets(); -} \ No newline at end of file + + /** + * Returns the aggregations + * + * @return array + */ + function getAggregations(); +} diff --git a/Paginator/RawPaginatorAdapter.php b/Paginator/RawPaginatorAdapter.php index 9a15695..10b4a1b 100644 --- a/Paginator/RawPaginatorAdapter.php +++ b/Paginator/RawPaginatorAdapter.php @@ -36,6 +36,11 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface * @var array for the facets */ private $facets; + + /** + * @var array for the aggregations + */ + private $aggregations; /** * @see PaginatorAdapterInterface::__construct @@ -82,6 +87,7 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface $resultSet = $this->searchable->search($query, $this->options); $this->totalHits = $resultSet->getTotalHits(); $this->facets = $resultSet->getFacets(); + $this->aggregations = $resultSet->getAggregations(); return $resultSet; } @@ -129,6 +135,19 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface return $this->facets; } + + /** + * Returns Aggregations + * + * @return mixed + */ + public function getAggregations() { + if (!isset($this->aggregations)) { + $this->aggregations = $this->searchable->search($this->query)->getAggregations(); + } + + return $this->aggregations; + } /** * Returns the Query diff --git a/Paginator/RawPartialResults.php b/Paginator/RawPartialResults.php index a4afb00..908986f 100644 --- a/Paginator/RawPartialResults.php +++ b/Paginator/RawPartialResults.php @@ -49,4 +49,16 @@ class RawPartialResults implements PartialResultsInterface return null; } -} \ No newline at end of file + + /** + * {@inheritDoc} + */ + public function getAggregations() + { + if ($this->resultSet->hasAggregations()) { + return $this->resultSet->getAggregations(); + } + + return null; + } +} diff --git a/Subscriber/PaginateElasticaQuerySubscriber.php b/Subscriber/PaginateElasticaQuerySubscriber.php index 0b7cfd6..e509cfa 100644 --- a/Subscriber/PaginateElasticaQuerySubscriber.php +++ b/Subscriber/PaginateElasticaQuerySubscriber.php @@ -32,6 +32,10 @@ class PaginateElasticaQuerySubscriber implements EventSubscriberInterface if (null != $facets) { $event->setCustomPaginationParameter('facets', $facets); } + $aggregations = $results->getAggregations(); + if (null != $aggregations) { + $event->setCustomPaginationParameter('aggregations', $aggregations); + } $event->stopPropagation(); } @@ -73,4 +77,4 @@ class PaginateElasticaQuerySubscriber implements EventSubscriberInterface 'knp_pager.items' => array('items', 1) ); } -} \ No newline at end of file +}