Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Added soft deleted to Meilisearch (OOTB included) #672

Merged
merged 2 commits into from
Dec 12, 2022

Conversation

kichetof
Copy link
Contributor

This PR add soft deleted for Meilisearch indexes.

  1. Out of the box: artisan scout:index 'App\Models\Users' will add filterable attributes __soft_deleted when model already use SoftDeletes trait and without any configuration 🤩
  2. Sync index: when you add SoftDeletes after index creation, you need to declare class in your scout config file. Instead of writing some repetition of:
\App\Models\User::class => [
    'filterableAttributes' => ['__soft_deleted']
],

You can simply write: \App\Models\User::class => [], or, more compact: \App\Models\User::class,

Your scout config file should look like:

'meilisearch' => [
    'host' => env('MEILISEARCH_HOST', 'http://localhost:7700'),
    'key' => env('MEILISEARCH_KEY', null),
    'index-settings' => [
        // full declaration
        \App\Models\User::class => [
            'filterableAttributes' => ['__soft_deleted']
        ],
        // compact declaration
        \App\Models\User::class => [],
        // more compact
        \App\Models\User::class,
    ],
],

Don't worry about multiple attributes definition, I tested a lot of times by querying Meilisearch index settings, and only one definition will be set.

@taylorotwell taylorotwell merged commit 53130b2 into laravel:9.x Dec 12, 2022
@driesvints
Copy link
Member

Hey @kichetof. Thanks for these, I just released them as v9.6.0. Do you maybe feel up to send a PR to the docs for this PR and #671?

https://laravel.com/docs/9.x/scout#configuring-filterable-data-for-meilisearch

@kichetof
Copy link
Contributor Author

Hello @driesvints I saw that Taylor updated before me, too fast for me 😎
I sent this PR to add index, delete-index and delete-all-indexes.

On writing the doc, I've see that delete-index couldn't receive a FQCN, I'll send a PR to update that.

@kichetof kichetof deleted the add_soft_deleted branch December 16, 2022 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants