Can we use a dynamic index name for Laravel Scout?
Heya!
In my current usecase I'm saving products in my Product model which can be in different languages. I want to create language specific indexes in Meilisearch and make Scout use those specific indexes.
To make this happen, I put this method in my Product model:
public function searchableAs()
{
return Str::of('products_')->append($this->getLanguage())->lower();
}
However, this will work when a single product has been updated. But when updating batches of products, it will take the index once and use it for the whole collection.
Are there any recommended methods to use dynamic indexes in Scout?
I don't think there is a specific option for dynamic indexes in Scout. I think the easiest option here is looping yourself over the collection of models and indexing each item one by one.
Another solution might be creating an index with all languages in one. Not sure how your data looks like, but that could be an option as well.
I doubt if 'looping yourself over the collection of models and indexing each item one by one' is the best way to go, since I'd ignore the best features of Scout this way.
Creating a single index for all languages in one sounds like the best solution cause I can use Scout as it is used to be. However, it doesn't feel 'clean' to put it all into one index, knowing I will always scope on a specific language...
But that's a Meilisearch specific question I guess...