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] Fix the sync index settings command not using the scout prefix #670

Merged
merged 4 commits into from
Dec 7, 2022

Conversation

tonysm
Copy link
Contributor

@tonysm tonysm commented Dec 6, 2022

Changed

  • Make the scout:sync-index-settings command aware of the scout prefix being used.

I was able to work around this by assigning the scout prefix to a variable inside the config file, like so:

return [
    'prefix' => $scoutPrefix = env('SCOUT_PREFIX', 'local_'),

    // ...

    'meilisearch' => [
        'host' => env('MEILISEARCH_HOST', 'http://localhost:7700'),
        'key' => env('MEILISEARCH_KEY', null),
        'index-settings' => [
            $scoutPrefix . 'users' => [
                'filterableAttributes'=> [
                    '__soft_deleted',
                    'id',
                    'name',
                ],
                'sortableAttributes' => [
                    'id',
                ],
            ],
        ],
    ],
];

But I figured the command could be made aware of the prefix instead. This change also allows defining the key as a model, so something like:

return [
    'meilisearch' => [
        'host' => env('MEILISEARCH_HOST', 'http://localhost:7700'),
        'key' => env('MEILISEARCH_KEY', null),
        'index-settings' => [
            App\Models\User::class => [
                'filterableAttributes'=> [
                    '__soft_deleted',
                    'id',
                    'name',
                ],
                'sortableAttributes' => [
                    'id',
                ],
            ],
        ],
    ],
];

Which uses the searchableAs() method inside the Searchable trait, which is already aware of the scout prefix.

When a string is passed instead of an FQCN, it will check if it already starts with the prefix before prepending it.

@tonysm tonysm changed the title Fix the sync index settings command not using the scout prefix [9.x] Fix the sync index settings command not using the scout prefix Dec 6, 2022
Copy link
Member

@driesvints driesvints left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @tonysm!

@taylorotwell taylorotwell merged commit 8489fac into laravel:9.x Dec 7, 2022
@tonysm tonysm deleted the index-settings-missing-prefix branch December 7, 2022 15:06
@driesvints
Copy link
Member

I released this as v9.5.1

@tommy66374
Copy link

I want upgrade to Scout v9.5.1

so we need change to use

        'index-settings' => [
            App\Models\User::class => [

instead of hardcoded the index name ?

Post Model

    public function searchableAs()
    {
        return 'posts_index';
    }

config\scout.php

        'index-settings' => [
            'posts_index' => [

@driesvints
Copy link
Member

@tommy66374 the old way should still work.

@tommy66374
Copy link

OK, Thank you very much, this very cool

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.

4 participants