teamtnt / laravel-scout-tntsearch-driver

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch
MIT License
1.09k stars 142 forks source link

Multiple Databases #247

Closed jmdrew closed 2 months ago

jmdrew commented 5 years ago

Would it be possible to use a separate DB connection for only searching index's to offload the main DB?

Namoshek commented 4 years ago

For whoever comes across this issue: yes, it is possible.

The package simply loads the default configuration and adds it to the scout.tntsearch configuration array, as can be found in the code rather easily: https://github.com/teamtnt/laravel-scout-tntsearch-driver/blob/9164556d238424f2a63ac6ed5c8c92a340b99dc0/src/TNTSearchScoutServiceProvider.php#L22-L25

This means you can simply add a different connection configuration to the tntsearch array in config/scout.php:

[
    // ... tntsearch settings as described in the README ...

    'driver' => 'mysql',
    'host' => env('SEARCH_DB_HOST', '127.0.0.1'),
    'port' => env('SEARCH_DB_PORT', '1433'),
    'database' => env('SEARCH_DB_DATABASE'),
    'username' => env('SEARCH_DB_USERNAME'),
    'password' => env('SEARCH_DB_PASSWORD'),
    // and other database related settings you may need
]