Laravel Scout (Meilisearch) - 说导入数据,但不说

问题描述 投票:0回答:4

我已经安装并配置了 meilisearch + Laravel Scout 包。

我的模特:

class Post extends Model
{
    use Searchable;
}

当我运行

php artisan scout:import 'App\Models\Post'
时,它返回:

Imported [App\Models\Post] models up to ID: 5
All [App\Models\Post] records have been imported.

但是当我检查索引时,它是空的。为什么?

正在创建索引,但未导入数据。

meilisearch 和 Scout 包的配置相同,适用于其他一些型号。

laravel full-text-search laravel-scout meilisearch
4个回答
9
投票

我自己刚刚遇到这个问题并遇到了你的问题。我不认为您正在指定索引中应该存储什么,是吗?

即在您的模型中,您是否创建了如下所示的

toSearchableArray
方法...

public function toSearchableArray(): array
{
    return [
        'name' => $this->name,
    ];
}

如果有,事实证明您的

toSearchableArray
方法 必须 还返回数组中的主键,否则记录不会被索引。

public function toSearchableArray(): array
{
    return [
        'id'   => $this->getKey(), // this *must* be defined
        'name' => $this->name,
    ];
}

5
投票

您可以尝试设置:

SCOUT_QUEUE=false

检查您的队列是否没有问题并再次运行导入。


4
投票

对于索引,您可以尝试:

php artisan scout:index posts

您的队列没有其他问题并再次运行导入。

如果您有

SCOUT_QUEUE=true
,请使用
php artisan queue:work --daemon
启动队列,您的数据将开始导入。


0
投票

确保模型中没有范围或将其注释掉:

php artisan scout import

没有会话,因此如果您的范围类似于

user_id == auth()->id
将不起作用。

© www.soinside.com 2019 - 2024. All rights reserved.