FOSElasticaBundle
FOSElasticaBundle copied to clipboard
Pagination, cannot get the right total count
It appears I cannot retrieve the right document total count for a query using fos-elastica-bundle. In my setup, the index holds 40 documents matching the query. The pagerfanta is initiated with the very same query and two calls are issued on it: getCurrentPageResults() and getNbResults(). The results are inconsistent as 10 documents are retrieved in the current page while the total returned count is 1.
Here is a code snippet from a custom repository extending FOS\ElasticaBundle\Repository to demonstrate the issue:
$esQuery = $myQueryBuilder->build($user, $search);
$results = $this->findPaginated($esQuery);
$results->setMaxPerPage(10);
$results->setCurrentPage(1);
echo "NBR OF DOCS FOR THIS PAGE=" . sizeof($results->getCurrentPageResults()) ."\n";
echo "TOTAL NBR OF DOCS=" . $results->getNbResults() ."\n";
Here is what gets printed:
NBR OF DOCS FOR THIS PAGE=10
TOTAL NBR OF DOCS=1
while it should be:
NBR OF DOCS FOR THIS PAGE=10
TOTAL NBR OF DOCS=40
BTW, I tried with a query with zero hits, getNbResults() still returns 1...
I really don't understand what I'm doing wrong so any advice would be greatly appreciated. The versions used are: Symfony v4.2.1 + friendsofsymfony/elastica-bundle v5.0.3 + pagerfanta/pagerfanta v1.1.0. If that's not an option, how can i get the total count with the bundle?