0

我尝试使用 laravel scout 将基于 SQL 的搜索迁移到 meilisearch。

目前整个搜索应该迁移到 meilisearch,包括所有过滤和排序选项。

A与(产品型号)product有关系:feedbacks

//returns all feedbacks for the product
public function allFeedbacks()
{
    return $this->hasMany('App\Models\Feedback');
}

我想包括对 meilisearch 的反馈量,但不是整个关系,因为排序不需要它。

如何添加其他字段以供 meilisearch 索引,而不将字段包含到 mySQL 数据库(feedback_amountfe)中?

4

1 回答 1

0

Product.php

public function toSearchableArray() {
  $fields = [
    'feedback_amount' => $this->allFeedbacks()->count(),
    'price' => $this->price,
    'other_stuff' => $this->other_stuff
  ];

  return $fields;
}

然后再次刷新并导入模型。

这将覆盖父项toSearchableArray(),因此您将希望包含您希望可搜索的任何其他字段。

于 2022-01-04T23:11:48.940 回答