From 45c93e67916888bb3e1947a1ba14b2b446f435e4 Mon Sep 17 00:00:00 2001 From: Yanick Witschi Date: Fri, 27 Dec 2024 11:51:22 +0100 Subject: [PATCH] Make sure identifiers are empty (#465) Fix and add missing parts of https://github.com/PHP-CMSIG/search/pull/460 --- .../laravel/src/Console/ReindexCommand.php | 10 ++++++++-- .../mezzio/src/Command/ReindexCommand.php | 10 +++++++++- .../spiral/src/Console/ReindexCommand.php | 15 ++++++++++++++- .../symfony/src/Command/ReindexCommand.php | 2 +- integrations/yii/src/Command/ReindexCommand.php | 10 +++++++++- 5 files changed, 41 insertions(+), 6 deletions(-) diff --git a/integrations/laravel/src/Console/ReindexCommand.php b/integrations/laravel/src/Console/ReindexCommand.php index 25c531c8..91c5a6af 100644 --- a/integrations/laravel/src/Console/ReindexCommand.php +++ b/integrations/laravel/src/Console/ReindexCommand.php @@ -28,7 +28,7 @@ final class ReindexCommand extends Command * * @var string */ - protected $signature = 'cmsig:seal:reindex {--engine= : The name of the engine} {--index= : The name of the index} {--drop : Drop the index before reindexing} {--bulk-size= : The bulk size for reindexing, defaults to 100.}'; + protected $signature = 'cmsig:seal:reindex {--engine= : The name of the engine} {--index= : The name of the index} {--drop : Drop the index before reindexing} {--bulk-size= : The bulk size for reindexing, defaults to 100.} {--datetime-boundary= : Do a partial update and limit to only documents that have been changed since a given datetime object.} {--identifiers= : Do a partial update and limit to only a comma-separated list of identifiers.}'; /** * The console command description. @@ -60,11 +60,17 @@ public function handle( $drop = $this->option('drop'); /** @var int $bulkSize */ $bulkSize = ((int) $this->option('bulk-size')) ?: 100; + /** @var \DateTimeImmutable|null $dateTimeBoundary */ + $dateTimeBoundary = $this->option('datetime-boundary') ? new \DateTimeImmutable((string) $this->option('datetime-boundary')) : null; // @phpstan-ignore-line + /** @var array $identifiers */ + $identifiers = \array_filter(\explode(',', (string) $this->option('identifiers'))); // @phpstan-ignore-line $reindexConfig = ReindexConfig::create() ->withIndex($indexName) ->withBulkSize($bulkSize) - ->withDropIndex($drop); + ->withDropIndex($drop) + ->withDateTimeBoundary($dateTimeBoundary) + ->withIdentifiers($identifiers); foreach ($engineRegistry->getEngines() as $name => $engine) { if ($engineName && $engineName !== $name) { diff --git a/integrations/mezzio/src/Command/ReindexCommand.php b/integrations/mezzio/src/Command/ReindexCommand.php index ecf412f1..bd011272 100644 --- a/integrations/mezzio/src/Command/ReindexCommand.php +++ b/integrations/mezzio/src/Command/ReindexCommand.php @@ -44,6 +44,8 @@ protected function configure(): void $this->addOption('index', null, InputOption::VALUE_REQUIRED, 'The name of the index to create the schema for.'); $this->addOption('drop', null, InputOption::VALUE_NONE, 'Drop the index before reindexing.'); $this->addOption('bulk-size', null, InputOption::VALUE_REQUIRED, 'The bulk size for reindexing, defaults to 100.'); + $this->addOption('datetime-boundary', null, InputOption::VALUE_REQUIRED, 'Do a partial update and limit to only documents that have been changed since a given datetime object.'); + $this->addOption('identifiers', null, InputOption::VALUE_REQUIRED, 'Do a partial update and limit to only a comma-separated list of identifiers.'); } protected function execute(InputInterface $input, OutputInterface $output): int @@ -57,11 +59,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int $drop = $input->getOption('drop'); /** @var int $bulkSize */ $bulkSize = ((int) $input->getOption('bulk-size')) ?: 100; // @phpstan-ignore-line + /** @var \DateTimeImmutable|null $dateTimeBoundary */ + $dateTimeBoundary = $input->getOption('datetime-boundary') ? new \DateTimeImmutable((string) $input->getOption('datetime-boundary')) : null; // @phpstan-ignore-line + /** @var array $identifiers */ + $identifiers = \array_filter(\explode(',', (string) $input->getOption('identifiers'))); // @phpstan-ignore-line $reindexConfig = ReindexConfig::create() ->withIndex($indexName) ->withBulkSize($bulkSize) - ->withDropIndex($drop); + ->withDropIndex($drop) + ->withDateTimeBoundary($dateTimeBoundary) + ->withIdentifiers($identifiers); foreach ($this->engineRegistry->getEngines() as $name => $engine) { if ($engineName && $engineName !== $name) { diff --git a/integrations/spiral/src/Console/ReindexCommand.php b/integrations/spiral/src/Console/ReindexCommand.php index 71ee2f51..e51c792e 100644 --- a/integrations/spiral/src/Console/ReindexCommand.php +++ b/integrations/spiral/src/Console/ReindexCommand.php @@ -42,6 +42,12 @@ final class ReindexCommand extends Command #[Option(name: 'bulk-size', description: 'The bulk size for reindexing, defaults to 100.')] private int $bulkSize = 100; + #[Option(name: 'datetime-boundary', description: 'Do a partial update and limit to only documents that have been changed since a given datetime object.')] + private string|null $datetimeBoundary = null; + + #[Option(name: 'identifiers', description: 'Do a partial update and limit to only a comma-separated list of identifiers.')] + private string|null $identifiers = null; + /** * @param iterable $reindexProviders */ @@ -54,10 +60,17 @@ public function __construct( public function __invoke( EngineRegistry $engineRegistry, ): int { + /** @var \DateTimeImmutable|null $dateTimeBoundary */ + $dateTimeBoundary = $this->datetimeBoundary ? new \DateTimeImmutable((string) $this->datetimeBoundary) : null; // @phpstan-ignore-line + /** @var array $identifiers */ + $identifiers = \array_filter(\explode(',', (string) $this->identifiers)); // @phpstan-ignore-line + $reindexConfig = ReindexConfig::create() ->withIndex($this->indexName) ->withBulkSize($this->bulkSize) - ->withDropIndex($this->drop); + ->withDropIndex($this->drop) + ->withDateTimeBoundary($dateTimeBoundary) + ->withIdentifiers($identifiers); foreach ($engineRegistry->getEngines() as $name => $engine) { if ($this->engineName && $this->engineName !== $name) { diff --git a/integrations/symfony/src/Command/ReindexCommand.php b/integrations/symfony/src/Command/ReindexCommand.php index 5e02d40d..2faad190 100644 --- a/integrations/symfony/src/Command/ReindexCommand.php +++ b/integrations/symfony/src/Command/ReindexCommand.php @@ -63,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int /** @var \DateTimeImmutable|null $dateTimeBoundary */ $dateTimeBoundary = $input->getOption('datetime-boundary') ? new \DateTimeImmutable((string) $input->getOption('datetime-boundary')) : null; // @phpstan-ignore-line /** @var array $identifiers */ - $identifiers = \explode(',', (string) $input->getOption('identifiers')); // @phpstan-ignore-line + $identifiers = \array_filter(\explode(',', (string) $input->getOption('identifiers'))); // @phpstan-ignore-line $reindexConfig = ReindexConfig::create() ->withIndex($indexName) diff --git a/integrations/yii/src/Command/ReindexCommand.php b/integrations/yii/src/Command/ReindexCommand.php index abe27c0c..3957d269 100644 --- a/integrations/yii/src/Command/ReindexCommand.php +++ b/integrations/yii/src/Command/ReindexCommand.php @@ -44,6 +44,8 @@ protected function configure(): void $this->addOption('index', null, InputOption::VALUE_REQUIRED, 'The name of the index to create the schema for.'); $this->addOption('drop', null, InputOption::VALUE_NONE, 'Drop the index before reindexing.'); $this->addOption('bulk-size', null, InputOption::VALUE_REQUIRED, 'The bulk size for reindexing, defaults to 100.'); + $this->addOption('datetime-boundary', null, InputOption::VALUE_REQUIRED, 'Do a partial update and limit to only documents that have been changed since a given datetime object.'); + $this->addOption('identifiers', null, InputOption::VALUE_REQUIRED, 'Do a partial update and limit to only a comma-separated list of identifiers.'); } protected function execute(InputInterface $input, OutputInterface $output): int @@ -57,11 +59,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int $drop = $input->getOption('drop'); /** @var int $bulkSize */ $bulkSize = ((int) $input->getOption('bulk-size')) ?: 100; // @phpstan-ignore-line + /** @var \DateTimeImmutable|null $dateTimeBoundary */ + $dateTimeBoundary = $input->getOption('datetime-boundary') ? new \DateTimeImmutable((string) $input->getOption('datetime-boundary')) : null; // @phpstan-ignore-line + /** @var array $identifiers */ + $identifiers = \array_filter(\explode(',', (string) $input->getOption('identifiers'))); // @phpstan-ignore-line $reindexConfig = ReindexConfig::create() ->withIndex($indexName) ->withBulkSize($bulkSize) - ->withDropIndex($drop); + ->withDropIndex($drop) + ->withDateTimeBoundary($dateTimeBoundary) + ->withIdentifiers($identifiers); foreach ($this->engineRegistry->getEngines() as $name => $engine) { if ($engineName && $engineName !== $name) {