Skip to content

Bug Report: Default Language Configuration in Laravel Scout Database Driver is Fixed to English #921

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

Closed
jjdevzinho opened this issue Mar 31, 2025 · 2 comments

Comments

@jjdevzinho
Copy link

Scout Version

10.14

Scout Driver

Database

Laravel Version

12.0

PHP Version

8.4.4

Database Driver & Version

Postgres 17

SDK Version

No response

Meilisearch CLI Version

No response

Description

Currently, when using PostgreSQL as the index for full-text search with Laravel Scout, the default language is set to English with no built-in way to modify it. This limitation restricts the use of the driver in applications requiring multilingual support, reducing the flexibility of Laravel Scout in global scenarios.

Expected Behavior:

There should be support for configuring the default language, either globally or at the model level, to enable compatibility with multilingual applications.

Current Behavior:

The default language for full-text search is fixed to English, with no options for modification.

Impact of the Issue:

The lack of support limits the usage of Laravel Scout in contexts where multiple languages are required, making it harder for developers to adopt the framework in global environments.

Possible Solution:

Enhance Laravel Scout with additional configurations to allow custom language settings:

1 - Global Configuration: Add an option in the file

return [
    'driver' => 'database',
    'database' => [
        'language' => 'portuguese', // Default language for full-text search
    ],
];

2 - Model-Level Configuration: Introduce a method in models for specifying the language.

class Post extends Model
{
    use Searchable;

    public function searchableLanguage(): string
    {
        return 'portuguese';
    }
}

3 - Method-Level Override: Provide an option to dynamically override the language when calling .

$posts = Post::search('Laravel', language: 'french')->get();

Steps to Reproduce:

1 - Set up PostgreSQL as the index for full-text search in Laravel Scout.
2 - Execute a search and note that the default language is English.
3 - Observe that there are no options to modify the language globally, at the model level, or through method calls.

Note:

I was unsure whether this should be categorized as a feature request or a bug. Since I couldn't submit it as a feature request, I am submitting it as a bug report instead. Apologies for any inconvenience this may cause.

Steps To Reproduce

1 - Set up PostgreSQL as the index for full-text search in Laravel Scout.
2 - Execute a search and note that the default language is English.
3 - Observe that there are no options to modify the language globally, at the model level, or through method calls.

@jjdevzinho
Copy link
Author

Additional Note:

After further analysis, I discovered that it is possible to configure the language for full-text searches at the model level using the annotation .

#[SearchUsingPrefix(['id'])]
#[SearchUsingFullText('name', ['language' => 'portuguese'])]
public function toSearchableArray(): array
{
    return [
        'id' => (int) $this->id,
        'name' => (string) $this->name,
    ];
}

However, this functionality is not clearly documented, which may lead to confusion and incorrect interpretations about the lack of support.

That said, I believe it would still be valuable to explore and document additional functionalities, such as global configurations or support within the method, to provide more flexibility in Laravel Scout. By keeping this issue open, I hope it serves as a proposal for these improvements and highlights the need for better documentation in Laravel Scout.

@crynobone
Copy link
Member

Feel free to submit a PR to the documentation repository: https://github.com/laravel/docs

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

No branches or pull requests

2 participants