Adds Search Sync Command

Adds an artisan app command that handles all of the search set-up and sync needed to get going.

`artisan app:search-sync`
This commit is contained in:
Refringe 2024-07-16 12:02:52 -04:00
parent fd5dc7cf20
commit cb636fd197
Signed by: Refringe
SSH Key Fingerprint: SHA256:t865XsQpfTeqPRBMN2G6+N8wlDjkgUCZF3WGW6O9N/k
3 changed files with 30 additions and 5 deletions

5
.github/README.md vendored
View File

@ -59,6 +59,11 @@ sail artisan migrate:fresh seed
sail artisan horizon
```
```
# Sync the local database with the Meilisearch server (requires horizon to be running):
sail artisan app:search-sync
```
```
# Install NPM dependencies from within the container:
sail npm install

View File

@ -0,0 +1,23 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
class SearchSync extends Command
{
protected $signature = 'app:search-sync';
protected $description = 'Syncs all search settings and indexes with the database data.';
public function handle(): void
{
Artisan::call('scout:delete-all-indexes');
Artisan::call('scout:sync-index-settings');
Artisan::call('scout:import', ['model' => '\App\Models\Mod']);
Artisan::call('scout:import', ['model' => '\App\Models\User']);
$this->info('The search synchronisation jobs have been added to the queue.');
}
}

View File

@ -52,11 +52,8 @@ class ImportHubData implements ShouldBeUnique, ShouldQueue
// Ensure that we've disconnected from the Hub database, clearing temporary tables.
DB::connection('mysql_hub')->disconnect();
// Reindex the Meilisearch index.
Artisan::call('scout:delete-all-indexes');
Artisan::call('scout:sync-index-settings');
Artisan::call('scout:import', ['model' => '\App\Models\Mod']);
Artisan::call('scout:import', ['model' => '\App\Models\User']);
// Re-sync search.
Artisan::call('app:search-sync');
}
/**