Skip to content

Commit

Permalink
[9.x] Added soft deleted to Meilisearch (OOTB included) (#672)
Browse files Browse the repository at this point in the history
* Added soft deleted to Meilisearch

* formatting

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
kichetof and taylorotwell authored Dec 12, 2022
1 parent 2bc384e commit 53130b2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Console/IndexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Exception;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str;
use Laravel\Scout\EngineManager;

Expand Down Expand Up @@ -59,6 +60,12 @@ public function handle(EngineManager $manager)
?? config('scout.'.$driver.'.index-settings.'.$class)
?? [];

if (isset($model) &&
config('scout.soft_delete', false) &&
in_array(SoftDeletes::class, class_uses_recursive($model))) {
$settings['filterableAttributes'][] = '__soft_deleted';
}

if ($settings) {
$engine->updateIndexSettings($name, $settings);
}
Expand Down
17 changes: 17 additions & 0 deletions src/Console/SyncIndexSettingsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Exception;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str;
use Laravel\Scout\EngineManager;

Expand Down Expand Up @@ -44,6 +45,22 @@ public function handle(EngineManager $manager)

if (count($indexes)) {
foreach ($indexes as $name => $settings) {
if (! is_array($settings)) {
$name = $settings;

$settings = [];
}

if (class_exists($name)) {
$model = new $name;
}

if (isset($model) &&
config('scout.soft_delete', false) &&
in_array(SoftDeletes::class, class_uses_recursive($model))) {
$settings['filterableAttributes'][] = '__soft_deleted';
}

$engine->updateIndexSettings($indexName = $this->indexName($name), $settings);

$this->info('Settings for the ['.$indexName.'] index synced successfully.');
Expand Down

0 comments on commit 53130b2

Please sign in to comment.