Skip to content
Advertisement

Unable to search with laravel-scout-tntsearch-driver

I just installed this package (laravel-scout-tntsearch-driver) and when using the search() method, I am getting the following error: PDOException with message 'SQLSTATE[HY000] [2002] Connection refused'

Running the command docker exec -it desk_php php artisan scout:import App\Models\TicketMessage result in:

Imported [AppModelsTicketMessage] models up to ID: 6
All [AppModelsTicketMessage] records have been imported.

After, I try to run the search in a tinker session and if fails with the Connection refused message.

docker exec -it desk_php php artisan tinker                                 
Psy Shell v0.9.12 (PHP 7.4.3 — cli) by Justin Hileman
>>> TicketMessage::search('test')->get()
PDOException with message 'SQLSTATE[HY000] [2002] Connection refused'

Here is my scout config file:

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Default Search Engine
    |--------------------------------------------------------------------------
    |
    | This option controls the default search connection that gets used while
    | using Laravel Scout. This connection is used when syncing all models
    | to the search service. You should adjust this based on your needs.
    |
    | Supported: "algolia", "null"
    |
    */

    'driver' => env('SCOUT_DRIVER', 'algolia'),

    /*
    |--------------------------------------------------------------------------
    | Index Prefix
    |--------------------------------------------------------------------------
    |
    | Here you may specify a prefix that will be applied to all search index
    | names used by Scout. This prefix may be useful if you have multiple
    | "tenants" or applications sharing the same search infrastructure.
    |
    */

    'prefix' => env('SCOUT_PREFIX', ''),

    /*
    |--------------------------------------------------------------------------
    | Queue Data Syncing
    |--------------------------------------------------------------------------
    |
    | This option allows you to control if the operations that sync your data
    | with your search engines are queued. When this is set to "true" then
    | all automatic data syncing will get queued for better performance.
    |
    */

    'queue' => env('SCOUT_QUEUE', false),

    /*
    |--------------------------------------------------------------------------
    | Chunk Sizes
    |--------------------------------------------------------------------------
    |
    | These options allow you to control the maximum chunk size when you are
    | mass importing data into the search engine. This allows you to fine
    | tune each of these chunk sizes based on the power of the servers.
    |
    */

    'chunk' => [
        'searchable' => 500,
        'unsearchable' => 500,
    ],

    /*
    |--------------------------------------------------------------------------
    | Soft Deletes
    |--------------------------------------------------------------------------
    |
    | This option allows to control whether to keep soft deleted records in
    | the search indexes. Maintaining soft deleted records can be useful
    | if your application still needs to search for the records later.
    |
    */

    'soft_delete' => false,

    /*
    |--------------------------------------------------------------------------
    | Algolia Configuration
    |--------------------------------------------------------------------------
    |
    | Here you may configure your Algolia settings. Algolia is a cloud hosted
    | search engine which works great with Scout out of the box. Just plug
    | in your application ID and admin API key to get started searching.
    |
    */

    'algolia' => [
        'id' => env('ALGOLIA_APP_ID', ''),
        'secret' => env('ALGOLIA_SECRET', ''),
    ],

    /*
    |--------------------------------------------------------------------------
    | TntSearch Configuration
    |--------------------------------------------------------------------------
    */

    'tntsearch' => [
        'storage'  => storage_path(), //place where the index files will be stored
        'fuzziness' => env('TNTSEARCH_FUZZINESS', false),
        'fuzzy' => [
            'prefix_length' => 2,
            'max_expansions' => 50,
            'distance' => 2
        ],
        'asYouType' => false,
        'searchBoolean' => env('TNTSEARCH_BOOLEAN', false),
    ],

];

Relevant .env settings

SCOUT_DRIVER=tntsearch
SCOUT_QUEUE=true

Any idea what I could be missing?

EDIT

Here is more details about what I have done.

I have installed the required SqLite extension and enabled it. I have added both Scout and Tnt to the providers array in the proper order. (Scout first)

After I run the import command, I noticed there is no index files generated in storage even if command show a success message.

Advertisement

Answer

From your comment I understand you have yet to configure Laravel to use SQLite by changing the default database setup.

In your config/database.php,

'default' => env('DB_CONNECTION', 'sqlite'),

(...)

'connections' => [
        'sqlite' => [
            'driver' => 'sqlite',
            'database' => storage_path('database.sqlite'),
            'prefix' => '',
        ],

Then, in your .env file you must change the DB_CONNECTION to DB_CONNECTION=sqlite.

In the end, to create the file,

touch database.sqlite
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement