Felix
Felix

Reputation: 2661

Weird bug with toSearchableArray with Laravel Scout and Meilisearch

This is my toSearchableArray for my Submission model:

public function toSearchableArray(): array
{
    return $this->only(['id', 'title', 'link', 'raw_text', 'subchan', 'nsfw', 'created_at_ts', 'file_path']);
}

Today I decided to add "file_path" to this. However I noticed that when going to the meilisearch dashboard, file_path wasn't being indexed after a flush (flush does work, all the records are deleted) and an import. I even tried php artisan scout:sync-index-settings. Now here's the weird part, I tried this again and I started removing some columns. I removed "raw_text" for example. But it was still indexing raw_text! What the heck?

In fact, I can completely remove toSearchableArray, and it still works. How is this possible? It just remembers what columns to index?

I figured this could only be a cache issue, so I tried php artisan cache:clear but the problem persists. I also tried restarting my machine, deleting all indexes, and nothing works.

This is probably the weirdest bug I've ever encountered using Laravel.

Upvotes: 1

Views: 268

Answers (1)

Felix
Felix

Reputation: 2661

The solution was that it wasn't enough to stop my queue worker and start it again, or restart my machine. It had do a php artisan queue:restart since it appears the worker was caching my toSearchableArray and this is the only way to clear that cache. Strange.

Upvotes: 0

Related Questions