reduce complexity of rebuild command

This commit is contained in:
Daniel Klabbers 2021-11-02 14:47:24 +01:00
parent 53651328bb
commit 4e6f560376
2 changed files with 22 additions and 27 deletions

View File

@ -18,5 +18,5 @@ return [
->get('/blomstra/search/{type}', 'blomstra.search', Api\Controllers\SearchController::class), ->get('/blomstra/search/{type}', 'blomstra.search', Api\Controllers\SearchController::class),
(new Flarum\Console) (new Flarum\Console)
->command(Commands\RebuildDocumentsCommand::class) ->command(Commands\BuildCommand::class)
]; ];

View File

@ -11,11 +11,9 @@ use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Queue\Queue; use Illuminate\Contracts\Queue\Queue;
use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Collection;
class RebuildDocumentsCommand extends Command class BuildCommand extends Command
{ {
protected $signature = 'blomstra:search:documents:rebuild protected $signature = 'blomstra:search:index
{--flush : Flushes ALL the documents inside the index}
{--mapping : Create property mappings: booleans, dates and fulltext searches}
{--max-id= : Limits for each object the number of items to seed}'; {--max-id= : Limits for each object the number of items to seed}';
protected $description = 'Rebuilds the complete search server with its documents.'; protected $description = 'Rebuilds the complete search server with its documents.';
@ -49,12 +47,12 @@ class RebuildDocumentsCommand extends Command
]; ];
// Flush the index. // Flush the index.
if ($this->option('flush')) {
$client->indices()->delete([ $client->indices()->delete([
'index' => $index, 'index' => $index,
'ignore_unavailable' => true 'ignore_unavailable' => true
]); ]);
// Create a new index.
$client->indices()->create([ $client->indices()->create([
'index' => $index, 'index' => $index,
'body' => [ 'body' => [
@ -69,14 +67,11 @@ class RebuildDocumentsCommand extends Command
] ]
] ]
]); ]);
}
if ($this->option('mapping')) {
$client->indices()->putMapping([ $client->indices()->putMapping([
'index' => $index, 'index' => $index,
'body' => $properties 'body' => $properties
]); ]);
}
/** @var Seeder $seeder */ /** @var Seeder $seeder */
foreach ($seeders as $seeder) { foreach ($seeders as $seeder) {