Skip to content

Commit 2007ff2

Browse files
authored
Merge pull request #391 from norkunas/update-settings-before-import
Update index settings before document import
2 parents 9d7643d + 3deb3c9 commit 2007ff2

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

src/Command/MeilisearchImportCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
114114

115115
$output->writeln('<info>Importing for index '.$entityClassName.'</info>');
116116

117+
if ($updateSettings) {
118+
$this->settingsUpdater->update($index['prefixed_name'], $responseTimeout, $prefix ? $prefix.$index['prefixed_name'] : null);
119+
}
120+
117121
$page = max(0, (int) $input->getOption('skip-batches'));
118122

119123
if ($page > 0) {
@@ -155,10 +159,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
155159
} while (\count($entities) >= $batchSize);
156160

157161
$manager->clear();
158-
159-
if ($updateSettings) {
160-
$this->settingsUpdater->update($index['prefixed_name'], $responseTimeout, $prefix ? $prefix.$index['prefixed_name'] : null);
161-
}
162162
}
163163

164164
if ($swapIndices) {

tests/Integration/Command/MeilisearchImportCommandTest.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,17 @@ public function testSearchImportAggregator(): void
206206
$commandTester = new CommandTester($command);
207207
$return = $commandTester->execute(['--indices' => $this->index->getUid()]);
208208

209-
$this->assertSame('Importing for index Meilisearch\Bundle\Tests\Entity\Post
210-
Indexed a batch of 6 / 6 Meilisearch\Bundle\Tests\Entity\Post entities into sf_phpunit__posts index (6 indexed since start)
211-
Indexed a batch of 6 / 6 Meilisearch\Bundle\Tests\Entity\Post entities into sf_phpunit__aggregated index (6 indexed since start)
209+
$this->assertSame(<<<'EOD'
210+
Importing for index Meilisearch\Bundle\Tests\Entity\Post
212211
Setting "stopWords" updated of "sf_phpunit__posts".
213212
Setting "filterableAttributes" updated of "sf_phpunit__posts".
214213
Setting "searchCutoffMs" updated of "sf_phpunit__posts".
215214
Setting "typoTolerance" updated of "sf_phpunit__posts".
215+
Indexed a batch of 6 / 6 Meilisearch\Bundle\Tests\Entity\Post entities into sf_phpunit__posts index (6 indexed since start)
216+
Indexed a batch of 6 / 6 Meilisearch\Bundle\Tests\Entity\Post entities into sf_phpunit__aggregated index (6 indexed since start)
216217
Done!
217-
', $commandTester->getDisplay());
218+
219+
EOD, $commandTester->getDisplay());
218220

219221
$this->assertSame(0, $return);
220222
}
@@ -262,12 +264,12 @@ public function testImportingIndexNameWithAndWithoutPrefix(): void
262264

263265
$this->assertSame(<<<'EOD'
264266
Importing for index Meilisearch\Bundle\Tests\Entity\Post
265-
Indexed a batch of 6 / 6 Meilisearch\Bundle\Tests\Entity\Post entities into sf_phpunit__posts index (6 indexed since start)
266-
Indexed a batch of 6 / 6 Meilisearch\Bundle\Tests\Entity\Post entities into sf_phpunit__aggregated index (6 indexed since start)
267267
Setting "stopWords" updated of "sf_phpunit__posts".
268268
Setting "filterableAttributes" updated of "sf_phpunit__posts".
269269
Setting "searchCutoffMs" updated of "sf_phpunit__posts".
270270
Setting "typoTolerance" updated of "sf_phpunit__posts".
271+
Indexed a batch of 6 / 6 Meilisearch\Bundle\Tests\Entity\Post entities into sf_phpunit__posts index (6 indexed since start)
272+
Indexed a batch of 6 / 6 Meilisearch\Bundle\Tests\Entity\Post entities into sf_phpunit__aggregated index (6 indexed since start)
271273
Done!
272274

273275
EOD, $commandTester->getDisplay());
@@ -291,12 +293,12 @@ public function testImportingIndexNameWithAndWithoutPrefix(): void
291293
$output = $commandTester->getDisplay();
292294
$this->assertSame(<<<'EOD'
293295
Importing for index Meilisearch\Bundle\Tests\Entity\Post
294-
Indexed a batch of 6 / 6 Meilisearch\Bundle\Tests\Entity\Post entities into sf_phpunit__posts index (6 indexed since start)
295-
Indexed a batch of 6 / 6 Meilisearch\Bundle\Tests\Entity\Post entities into sf_phpunit__aggregated index (6 indexed since start)
296296
Setting "stopWords" updated of "sf_phpunit__posts".
297297
Setting "filterableAttributes" updated of "sf_phpunit__posts".
298298
Setting "searchCutoffMs" updated of "sf_phpunit__posts".
299299
Setting "typoTolerance" updated of "sf_phpunit__posts".
300+
Indexed a batch of 6 / 6 Meilisearch\Bundle\Tests\Entity\Post entities into sf_phpunit__posts index (6 indexed since start)
301+
Indexed a batch of 6 / 6 Meilisearch\Bundle\Tests\Entity\Post entities into sf_phpunit__aggregated index (6 indexed since start)
300302
Done!
301303

302304
EOD, $commandTester->getDisplay());
@@ -393,11 +395,11 @@ public function testImportWithDynamicSettings(): void
393395

394396
$this->assertSame(<<<'EOD'
395397
Importing for index Meilisearch\Bundle\Tests\Entity\DynamicSettings
396-
Indexed a batch of 6 / 6 Meilisearch\Bundle\Tests\Entity\DynamicSettings entities into sf_phpunit__dynamic_settings index (6 indexed since start)
397398
Setting "filterableAttributes" updated of "sf_phpunit__dynamic_settings".
398399
Setting "searchableAttributes" updated of "sf_phpunit__dynamic_settings".
399400
Setting "stopWords" updated of "sf_phpunit__dynamic_settings".
400401
Setting "synonyms" updated of "sf_phpunit__dynamic_settings".
402+
Indexed a batch of 6 / 6 Meilisearch\Bundle\Tests\Entity\DynamicSettings entities into sf_phpunit__dynamic_settings index (6 indexed since start)
401403
Done!
402404

403405
EOD, $importOutput);
@@ -432,14 +434,14 @@ public function testImportUpdatesSettingsOnce(): void
432434

433435
$this->assertSame(<<<'EOD'
434436
Importing for index Meilisearch\Bundle\Tests\Entity\Post
435-
Indexed a batch of 2 / 2 Meilisearch\Bundle\Tests\Entity\Post entities into sf_phpunit__posts index (2 indexed since start)
436-
Indexed a batch of 2 / 2 Meilisearch\Bundle\Tests\Entity\Post entities into sf_phpunit__aggregated index (2 indexed since start)
437-
Indexed a batch of 2 / 2 Meilisearch\Bundle\Tests\Entity\Post entities into sf_phpunit__posts index (4 indexed since start)
438-
Indexed a batch of 2 / 2 Meilisearch\Bundle\Tests\Entity\Post entities into sf_phpunit__aggregated index (4 indexed since start)
439437
Setting "stopWords" updated of "sf_phpunit__posts".
440438
Setting "filterableAttributes" updated of "sf_phpunit__posts".
441439
Setting "searchCutoffMs" updated of "sf_phpunit__posts".
442440
Setting "typoTolerance" updated of "sf_phpunit__posts".
441+
Indexed a batch of 2 / 2 Meilisearch\Bundle\Tests\Entity\Post entities into sf_phpunit__posts index (2 indexed since start)
442+
Indexed a batch of 2 / 2 Meilisearch\Bundle\Tests\Entity\Post entities into sf_phpunit__aggregated index (2 indexed since start)
443+
Indexed a batch of 2 / 2 Meilisearch\Bundle\Tests\Entity\Post entities into sf_phpunit__posts index (4 indexed since start)
444+
Indexed a batch of 2 / 2 Meilisearch\Bundle\Tests\Entity\Post entities into sf_phpunit__aggregated index (4 indexed since start)
443445
Done!
444446

445447
EOD, $importOutput);

0 commit comments

Comments
 (0)