【问题标题】:How to index only relevant fields of my model using Algolia search?如何使用 Algolia 搜索仅索引我的模型的相关字段?
【发布时间】:2017-10-19 02:05:10
【问题描述】:

我正在将 Algolia 搜索整合到我的一个应用程序中,并且达到了 10 KB 的文档大小限制。我只想索引模型中的某些字段,而不是全部。我正在使用 mongo,它嵌入了我不关心的相关文档。

我按照以下说明操作:https://laravel.com/docs/5.3/scout

现在,当我为数据编制索引时,我收到警告,我的 2000 个左右的文档中有大约 100 个超过了 10 KB 大小。

我如何告诉 Algolia 我只想索引某些字段而忽略一些其他数据,例如关系或嵌入文档?

【问题讨论】:

    标签: mongodb algolia


    【解决方案1】:

    您可以在要添加可搜索特征的类中使用 Laravel 的 toSearchableArray。因为你只包括你真正想要搜索的部分。

    public function toSearchableArray() {
      $array = $this->toArray();
      $array = [
        'id' => $this->id,
        'name' => $this->name,
        'description' => $this->description,
        'price' => (int)$this->price,
        'likes' => (int)$this->likes,
        'slug' => $this->slug
      ];
      return $array;
    }
    

    这就是你要找的吗?

    【讨论】:

    • 注意数组一定要最后返回
    猜你喜欢
    • 1970-01-01
    • 2014-02-18
    • 2014-03-09
    • 2016-06-26
    • 1970-01-01
    • 2015-05-08
    • 1970-01-01
    • 1970-01-01
    • 2017-09-21
    相关资源
    最近更新 更多