From 4e6f56037665fde2793d86d89ea390cd2e3a103c Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Tue, 2 Nov 2021 14:47:24 +0100 Subject: [PATCH] reduce complexity of rebuild command --- extend.php | 2 +- ...dDocumentsCommand.php => BuildCommand.php} | 47 +++++++++---------- 2 files changed, 22 insertions(+), 27 deletions(-) rename src/Commands/{RebuildDocumentsCommand.php => BuildCommand.php} (69%) diff --git a/extend.php b/extend.php index 7da78b1..8ec76e9 100644 --- a/extend.php +++ b/extend.php @@ -18,5 +18,5 @@ return [ ->get('/blomstra/search/{type}', 'blomstra.search', Api\Controllers\SearchController::class), (new Flarum\Console) - ->command(Commands\RebuildDocumentsCommand::class) + ->command(Commands\BuildCommand::class) ]; diff --git a/src/Commands/RebuildDocumentsCommand.php b/src/Commands/BuildCommand.php similarity index 69% rename from src/Commands/RebuildDocumentsCommand.php rename to src/Commands/BuildCommand.php index 7dc1097..1de8483 100644 --- a/src/Commands/RebuildDocumentsCommand.php +++ b/src/Commands/BuildCommand.php @@ -11,11 +11,9 @@ use Illuminate\Contracts\Container\Container; use Illuminate\Contracts\Queue\Queue; use Illuminate\Database\Eloquent\Collection; -class RebuildDocumentsCommand extends Command +class BuildCommand extends Command { - protected $signature = 'blomstra:search:documents:rebuild - {--flush : Flushes ALL the documents inside the index} - {--mapping : Create property mappings: booleans, dates and fulltext searches} + protected $signature = 'blomstra:search:index {--max-id= : Limits for each object the number of items to seed}'; protected $description = 'Rebuilds the complete search server with its documents.'; @@ -49,34 +47,31 @@ class RebuildDocumentsCommand extends Command ]; // Flush the index. - if ($this->option('flush')) { - $client->indices()->delete([ - 'index' => $index, - 'ignore_unavailable' => true - ]); + $client->indices()->delete([ + 'index' => $index, + 'ignore_unavailable' => true + ]); - $client->indices()->create([ - 'index' => $index, - 'body' => [ - 'settings' => [ - 'analysis' => [ - 'analyzer' => [ - 'flarum_analyzer' => [ - 'type' => $settings->get('blomstra-search.analyzer-language') ?: 'english' - ] + // Create a new index. + $client->indices()->create([ + 'index' => $index, + 'body' => [ + 'settings' => [ + 'analysis' => [ + 'analyzer' => [ + 'flarum_analyzer' => [ + 'type' => $settings->get('blomstra-search.analyzer-language') ?: 'english' ] ] ] ] - ]); - } + ] + ]); - if ($this->option('mapping')) { - $client->indices()->putMapping([ - 'index' => $index, - 'body' => $properties - ]); - } + $client->indices()->putMapping([ + 'index' => $index, + 'body' => $properties + ]); /** @var Seeder $seeder */ foreach ($seeders as $seeder) {