From b09bf3cf10b468a75f032624ed54047d2119e506 Mon Sep 17 00:00:00 2001 From: Adrien Morel Date: Wed, 26 Nov 2014 16:25:23 +0100 Subject: [PATCH] RawPaginatorAdapter::getTotalHits() can retrieve the genuine total hits returned by elasticsearch --- Paginator/RawPaginatorAdapter.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Paginator/RawPaginatorAdapter.php b/Paginator/RawPaginatorAdapter.php index f05205a..9a15695 100644 --- a/Paginator/RawPaginatorAdapter.php +++ b/Paginator/RawPaginatorAdapter.php @@ -100,15 +100,18 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface /** * Returns the number of results. * + * @param boolean $genuineTotal make the function return the `hits.total` + * value of the search result in all cases, instead of limiting it to the + * `size` request parameter. * @return integer The number of results. */ - public function getTotalHits() + public function getTotalHits($genuineTotal = false) { if ( ! isset($this->totalHits)) { $this->totalHits = $this->searchable->search($this->query)->getTotalHits(); } - return $this->query->hasParam('size') + return $this->query->hasParam('size') && !$genuineTotal ? min($this->totalHits, (integer) $this->query->getParam('size')) : $this->totalHits; }