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,34 +47,31 @@ 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 ]);
]);
$client->indices()->create([ // Create a new index.
'index' => $index, $client->indices()->create([
'body' => [ 'index' => $index,
'settings' => [ 'body' => [
'analysis' => [ 'settings' => [
'analyzer' => [ 'analysis' => [
'flarum_analyzer' => [ 'analyzer' => [
'type' => $settings->get('blomstra-search.analyzer-language') ?: 'english' 'flarum_analyzer' => [
] 'type' => $settings->get('blomstra-search.analyzer-language') ?: 'english'
] ]
] ]
] ]
] ]
]); ]
} ]);
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) {