首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法与laravel- search驱动器搜索

无法与laravel- search驱动器搜索
EN

Stack Overflow用户
提问于 2020-03-09 18:45:11
回答 1查看 856关注 0票数 2

我刚刚安装了这个软件包(laravel-scout驱动程序),在使用search()方法时,我得到了以下错误:PDOException with message 'SQLSTATE[HY000] [2002] Connection refused'

运行命令docker exec -it desk_php php artisan scout:import App\\Models\\TicketMessage将得到以下结果:

代码语言:javascript
复制
Imported [App\Models\TicketMessage] models up to ID: 6
All [App\Models\TicketMessage] records have been imported.

之后,我尝试在修补程序会话中运行搜索,如果连接拒绝消息失败。

代码语言:javascript
复制
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'

这是我的童子军配置文件:

代码语言:javascript
复制
<?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),
    ],

];

相关.env设置

代码语言:javascript
复制
SCOUT_DRIVER=tntsearch
SCOUT_QUEUE=true

知道我可能错过了什么吗?

编辑

以下是我所做工作的更多细节。

我已经安装了所需的SqLite扩展并启用了它。我已经将Scout和Tnt按正确的顺序添加到提供者数组中。(童子军第一)

运行import命令后,我注意到存储中没有生成索引文件,即使命令显示了成功消息。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-09 19:46:49

从您的评论中,我了解到您还需要通过更改默认的数据库设置来配置Laravel来使用SQLite。

在config/database.php中,

代码语言:javascript
复制
'default' => env('DB_CONNECTION', 'sqlite'),

(...)

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

然后,在.env文件中,必须将DB_CONNECTION更改为DB_CONNECTION=sqlite

最后,要创建文件,

代码语言:javascript
复制
touch database.sqlite
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60606599

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档