X 4*_* IR 4 full-text-search laravel laravel-scout meilisearch
我已经安装并配置了 meilisearch + Laravel Scout 包。
我的型号:
class Post extends Model
{
use Searchable;
}
Run Code Online (Sandbox Code Playgroud)
当我运行时php artisan scout:import 'App\Models\Post'它返回:
Imported [App\Models\Post] models up to ID: 5
All [App\Models\Post] records have been imported.
Run Code Online (Sandbox Code Playgroud)
但当我检查索引时,它是空的。为什么?
正在创建索引,但未导入数据。
meilisearch 和 Scout 包的相同配置适用于其他一些型号。
我自己刚刚遇到这个问题并遇到了你的问题。我不认为您指定了索引中应存储的内容,是吗?
即在您的模型中,您是否创建了toSearchableArray如下所示的方法......
public function toSearchableArray(): array
{
return [
'name' => $this->name,
];
}
Run Code Online (Sandbox Code Playgroud)
如果有,则事实证明您的toSearchableArray方法还必须返回数组中的主键,否则记录不会被索引。
public function toSearchableArray(): array
{
return [
'id' => $this->getKey(), // this *must* be defined
'name' => $this->name,
];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4652 次 |
| 最近记录: |