Adding Index to Laravel Scout Conditionally (Algolia)

北慕城南 提交于 2019-12-24 13:07:06

问题


I'm trying to add index to Algolia using Laravel Scout based on a condition. For example I have a Article model and I only want to add this article to Algolia if the article is active. My first approach was this:

public function toSearchableArray()
{
   if($this->active) return $record;
   return [];

}

this only adds the active records but still attempts to add empty arrays which is considered as Operation in algolia ( I will be charged for it). The second approach was to use shouldBesearchable() function from scout:

public function shouldBeSearchable()
{
    if($this->active) return true;
    return false;

}

This doesn't work with php artisan scout:import "App\Article". Has anyone faced a similar problem?


回答1:


It was a bug in Laravel Scout, shouldBeSearchable is not release yet (on master branch) so you may experience some issue like this one.

Although, good news: it was just fixed by this PR. https://github.com/laravel/scout/pull/250



来源:https://stackoverflow.com/questions/48191954/adding-index-to-laravel-scout-conditionally-algolia

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!