added --recreate and --only to command
This commit is contained in:
parent
c1c5af8ed6
commit
bcdf625603
|
|
@ -17,7 +17,9 @@ class BuildCommand extends Command
|
||||||
protected $signature = 'blomstra:search:index
|
protected $signature = 'blomstra:search:index
|
||||||
{--max-id= : Limits for each object the number of items to seed}
|
{--max-id= : Limits for each object the number of items to seed}
|
||||||
{--chunk-size= : Size of the chunks to dispatch into jobs}
|
{--chunk-size= : Size of the chunks to dispatch into jobs}
|
||||||
{--throttle= : Number of seconds to wait between pushing to the queue}';
|
{--throttle= : Number of seconds to wait between pushing to the queue}
|
||||||
|
{--only= : type to run seeder for, eg discussions or posts}
|
||||||
|
{--recreate : create or recreate the index}';
|
||||||
protected $description = 'Rebuilds the complete search server with its documents.';
|
protected $description = 'Rebuilds the complete search server with its documents.';
|
||||||
|
|
||||||
public function handle(Container $container)
|
public function handle(Container $container)
|
||||||
|
|
@ -49,35 +51,41 @@ class BuildCommand extends Command
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
// Flush the index.
|
if ($this->option('recreate')) {
|
||||||
$client->indices()->delete([
|
// Flush the index.
|
||||||
'index' => $index,
|
$client->indices()->delete([
|
||||||
'ignore_unavailable' => true
|
'index' => $index,
|
||||||
]);
|
'ignore_unavailable' => true
|
||||||
|
]);
|
||||||
|
|
||||||
// Create a new index.
|
// Create a new index.
|
||||||
$client->indices()->create([
|
$client->indices()->create([
|
||||||
'index' => $index,
|
'index' => $index,
|
||||||
'body' => [
|
'body' => [
|
||||||
'settings' => [
|
'settings' => [
|
||||||
'analysis' => [
|
'analysis' => [
|
||||||
'analyzer' => [
|
'analyzer' => [
|
||||||
'flarum_analyzer' => [
|
'flarum_analyzer' => [
|
||||||
'type' => $settings->get('blomstra-search.analyzer-language') ?: 'english'
|
'type' => $settings->get('blomstra-search.analyzer-language') ?: 'english'
|
||||||
|
]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
]
|
]);
|
||||||
]);
|
|
||||||
|
|
||||||
$client->indices()->putMapping([
|
$client->indices()->putMapping([
|
||||||
'index' => $index,
|
'index' => $index,
|
||||||
'body' => $properties
|
'body' => $properties
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$only = $this->option('only');
|
||||||
|
|
||||||
/** @var Seeder $seeder */
|
/** @var Seeder $seeder */
|
||||||
foreach ($seeders as $seeder) {
|
foreach ($seeders as $seeder) {
|
||||||
|
if ($only && $seeder->type() !== $only) continue;
|
||||||
|
|
||||||
$seeder->query()
|
$seeder->query()
|
||||||
->when($this->option('max-id'), function ($query, $id) {
|
->when($this->option('max-id'), function ($query, $id) {
|
||||||
$query->where('id', '<=', $id);
|
$query->where('id', '<=', $id);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue