I’m trying to add an index to Algolia using Laravel Scout based on a condition. For example, I have an Article
model and I only want to add this article to Algolia if the article is active
.My first method is:
public function toSearchableArray() { if($this->active) return $record; return []; }
This will only add active records, but will still try to add empty arrays, which are treated as operations in algolia (which I will charge for). The second way is to use shouldBesearchable()
Scout functions:
public function shouldBeSearchable() { if($this->active) return true; return false; }
This doesn’t workphp artisan scout:import "App\Article"
. Has anyone encountered a similar problem?
1> Julien Bourd..:
This is a bug in Laravel Scout, shouldBeSearchable
has not been released yet ( on the master branch), so you might run into issues like this.
Good news though: it’s just fixed by this PR.
https://github.com/laravel/scout/pull/250