Skip to content

Commit

Permalink
fix: Use Paginator to avoid pagination issues during Solr node indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisemaupate committed Apr 26, 2022
1 parent 92b38ef commit f43cae9
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/SearchEngine/Indexer/NodesSourcesIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace RZ\Roadiz\CoreBundle\SearchEngine\Indexer;

use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\Tools\Pagination\Paginator;
use RZ\Roadiz\CoreBundle\Entity\NodesSources;
use Solarium\Exception\HttpException;
use Solarium\Plugin\BufferedAdd\BufferedAdd;
Expand Down Expand Up @@ -98,23 +99,27 @@ public function reindexAll(int $batchCount = 1, int $batchNumber = 0): void
$limit = $count - $offset;
$baseQb->setMaxResults($limit)->setFirstResult($offset);
if (null !== $this->io) {
$this->io->note('Batch mode enabled (last): Limit to ' . $limit . ', offset from ' . $offset);
$this->io->note(sprintf('Batch mode enabled (last): from %d to %d', $offset, ($offset + $limit) - 1));
}
} else {
$baseQb->setMaxResults($limit)->setFirstResult($offset);
if (null !== $this->io) {
$this->io->note('Batch mode enabled: Limit to ' . $limit . ', offset from ' . $offset);
$this->io->note(sprintf('Batch mode enabled: from %d to %d', $offset, ($offset + $limit) - 1));
}
}
$count = $limit;
}
$q = $baseQb->getQuery();

/*
* Must use Paginator to avoid missing items due to SQL pagination issues with offset and limit
*/
$paginator = new Paginator($baseQb->getQuery(), true);

if (null !== $this->io) {
$this->io->progressStart($count);
}

foreach ($q->toIterable() as $row) {
foreach ($paginator as $row) {
$solarium = $this->solariumFactory->createWithNodesSources($row);
$solarium->createEmptyDocument($update);
$solarium->index();
Expand Down

0 comments on commit f43cae9

Please sign in to comment.