Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/Command/MeiliSearchImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ protected function configure(): void
null,
InputOption::VALUE_NONE,
'Update settings related to indices to the search engine'
);
)
->addOption('batch-size', null, InputOption::VALUE_REQUIRED);
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand All @@ -64,6 +65,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$entitiesToIndex = array_unique($indexes->toArray(), SORT_REGULAR);
$batchSize = $input->getOption('batch-size');
$batchSize = ctype_digit($batchSize) ? (int) $batchSize : $config->get('batchSize');

/** @var array $index */
foreach ($entitiesToIndex as $index) {
Expand All @@ -82,8 +85,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$entities = $repository->findBy(
[],
null,
$config->get('batchSize'),
$config->get('batchSize') * $page
$batchSize,
$batchSize * $page
);

$responses = $this->formatIndexingResponse($this->searchService->index($manager, $entities));
Expand Down Expand Up @@ -125,7 +128,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

++$page;
} while (count($entities) >= $config->get('batchSize'));
} while (count($entities) >= $batchSize);

$manager->clear();
}
Expand Down
28 changes: 28 additions & 0 deletions tests/Integration/CommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,34 @@ public function testSearchImportAndClearAndDeleteWithoutIndices(): void
EOD, $clearOutput);
}

public function testSearchImportWithCustomBatchSize(): void
{
for ($i = 0; $i <= 10; ++$i) {
$this->createPage($i);
}

$importCommand = $this->application->find('meili:import');
$importCommandTester = new CommandTester($importCommand);
$importCommandTester->execute([
'--indices' => 'pages',
'--batch-size' => '2',
]);

$importOutput = $importCommandTester->getDisplay();

$this->assertSame(<<<'EOD'
Importing for index MeiliSearch\Bundle\Test\Entity\Page
Indexed 2 / 2 MeiliSearch\Bundle\Test\Entity\Page entities into sf_phpunit__pages index
Indexed 2 / 2 MeiliSearch\Bundle\Test\Entity\Page entities into sf_phpunit__pages index
Indexed 2 / 2 MeiliSearch\Bundle\Test\Entity\Page entities into sf_phpunit__pages index
Indexed 2 / 2 MeiliSearch\Bundle\Test\Entity\Page entities into sf_phpunit__pages index
Indexed 2 / 2 MeiliSearch\Bundle\Test\Entity\Page entities into sf_phpunit__pages index
Indexed 1 / 1 MeiliSearch\Bundle\Test\Entity\Page entities into sf_phpunit__pages index
Done!

EOD, $importOutput);
}

/**
* Importing 'Tag' and 'Link' into the same 'tags' index.
*/
Expand Down