我正在尝试根据条件使用Laravel Scout为Algolia添加索引。例如,我有Article
模型,如果文章是active
,我只想将此文章添加到Algolia。我的第一个方法是:
public function toSearchableArray()
{
if($this->active) return $record;
return [];
}
这只会添加活动记录,但仍会尝试添加空数组,这些数组在algolia中被视为操作(我将收取费用)。第二种方法是使用来自scout的shouldBesearchable()
函数:
public function shouldBeSearchable()
{
if($this->active) return true;
return false;
}
这不适用于php artisan scout:import "App\Article"
。有没有人遇到过类似的问题?
答案 0 :(得分:5)
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