From 2eeb075b492b27c054f52e49c2a738422b007060 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Fri, 6 Jan 2023 00:45:55 +0100 Subject: [PATCH 1/2] fix: fix meilisearch indexes import --- app/Console/Commands/SetupDummyAccount.php | 2 +- app/Console/Commands/SetupScout.php | 50 ++++++++++++++++------ 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/app/Console/Commands/SetupDummyAccount.php b/app/Console/Commands/SetupDummyAccount.php index 92323e4b0..e87ddaddd 100644 --- a/app/Console/Commands/SetupDummyAccount.php +++ b/app/Console/Commands/SetupDummyAccount.php @@ -91,7 +91,7 @@ private function wipeAndMigrateDB(): void } else { $this->artisan('☐ Migration of the database', 'migrate:fresh', ['--force' => true]); } - $this->artisan('☐ Reset search engine', 'scout:setup', ['--force' => true]); + $this->artisan('☐ Reset search engine', 'scout:setup', ['--force' => true, '--flush' => true]); } private function stop(): void diff --git a/app/Console/Commands/SetupScout.php b/app/Console/Commands/SetupScout.php index 4b4b46fe9..7e74fcc09 100644 --- a/app/Console/Commands/SetupScout.php +++ b/app/Console/Commands/SetupScout.php @@ -2,9 +2,6 @@ namespace App\Console\Commands; -use App\Models\Contact; -use App\Models\Group; -use App\Models\Note; use Illuminate\Console\Command; use Illuminate\Console\ConfirmableTrait; use Symfony\Component\Console\Output\OutputInterface; @@ -22,6 +19,8 @@ class SetupScout extends Command * @var string */ protected $signature = 'scout:setup + {--flush : Flush the indexes.} + {--import : Import the models into the search index.} {--force : Force the operation to run when in production.}'; /** @@ -37,7 +36,8 @@ class SetupScout extends Command public function handle(): void { if ($this->confirmToProceed()) { - $this->scout(); + $this->scoutConfigure(); + $this->scoutImport(); } } @@ -46,19 +46,45 @@ public function handle(): void * * @return void */ - protected function scout(): void + protected function scoutConfigure(): void { - if (config('scout.driver') !== null) { - $this->artisan('☐ Flush search engine', 'scout:flush', ['model' => Note::class, '--verbose' => true]); - $this->artisan('☐ Flush search engine', 'scout:flush', ['model' => Contact::class, '--verbose' => true]); - $this->artisan('☐ Flush search engine', 'scout:flush', ['model' => Group::class, '--verbose' => true]); + if (config('scout.driver') === 'meilisearch' && (config('scout.meilisearch.host')) !== '') { + $this->artisan('☐ Updating indexes on Meilisearch', 'scout:sync-index-settings', ['--verbose' => true]); } + } - if (config('scout.driver') === 'meilisearch' && (config('scout.meilisearch.host')) !== '') { - $this->artisan('☐ Creating indexes on Meilisearch', 'scout:sync-index-settings', ['--verbose' => true]); + /** + * Import models. + * + * @return void + */ + protected function scoutFlush(): void + { + if (config('scout.driver') !== null && $this->option('flush')) { + foreach (config('scout.meilisearch.index-settings') as $index => $settings) { + $name = (new $index)->getTable(); + $this->artisan("☐ Flush {$name} index", 'scout:flush', ['model' => $index, '--verbose' => true]); + } + + $this->info('✓ Indexes flushed'); } + } + + /** + * Import models. + * + * @return void + */ + protected function scoutImport(): void + { + if (config('scout.driver') !== null && $this->option('import')) { + foreach (config('scout.meilisearch.index-settings') as $index => $settings) { + $name = (new $index)->getTable(); + $this->artisan("☐ Import {$name}", 'scout:import', ['model' => $index, '--verbose' => true]); + } - $this->info('✓ Indexes created'); + $this->info('✓ Indexes imported'); + } } private function artisan(string $message, string $command, array $options = []) From 40aab682378cf5a9b97c3346c544d803acb89b10 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Fri, 6 Jan 2023 00:48:05 +0100 Subject: [PATCH 2/2] fix --- app/Console/Commands/SetupScout.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Console/Commands/SetupScout.php b/app/Console/Commands/SetupScout.php index 7e74fcc09..886201fef 100644 --- a/app/Console/Commands/SetupScout.php +++ b/app/Console/Commands/SetupScout.php @@ -37,6 +37,7 @@ public function handle(): void { if ($this->confirmToProceed()) { $this->scoutConfigure(); + $this->scoutFlush(); $this->scoutImport(); } }