Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

fix: fix meilisearch indexes import #378

Merged
merged 2 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Console/Commands/SetupDummyAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 39 additions & 12 deletions app/Console/Commands/SetupScout.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.}';

/**
Expand All @@ -37,7 +36,9 @@ class SetupScout extends Command
public function handle(): void
{
if ($this->confirmToProceed()) {
$this->scout();
$this->scoutConfigure();
$this->scoutFlush();
$this->scoutImport();
}
}

Expand All @@ -46,19 +47,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 = [])
Expand Down