Azoruk's avatar

Is it just me or does Laravel Scout suck?

For reference, I use Meilisearch with Scout. But these problems were identical when using Elasticsearch.

I feel like Scout is just... really lacking in features.

So far starters, to define which columns of a table should be searchable I have specify them in my model with "toSearchableArray".

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

Great. However, taking out "id" will result in non-discoverable elements within the search because by default the id is the primary key used for identifying a document. So you HAVE TO leave 'id' in toSearchableArray. This effectively exposes all your IDs for the table, as someone could just search "5341" and it would return the row with the primary ID of "5341".

Or let's say I want to filter by a column that isn't searchable, like created_at.

Comment::search($query, ['filters' => 'created_at > 795484800'])

Sorry, that doesn't work because created_at isn't indexed. And to index it you have to add it to toSearchableArray. And that makes it that column searchable, even if you don't want it to be.

Or let's take where clauses. Scout only allows for basic where clauses (https://laravel.com/docs/8.x/scout#where-clauses). And this is seriously the most basic where clauses, it doesn't even allow for where != equal to.

Has anyone else had similar experiences with Scout?

0 likes
2 replies
martinbean's avatar

@azoruk Well yeah, you’ve just described Scout’s feature set. I guess it depends on what your expectations are versus reality. If you go in expecting it to do X, Y, Z but it only does X then yeah, you’re going to be disappointed.

I don’t really know what litmus test the developers used when creating Scout. I’m guessing they maybe choose the limited feature set for the most compatiblity between search providers. I’m guessing if you need something more, you could look at integrating with your search provider of choice (be it Algolia, Meilisearch, Elastic Search, or other) to benefit from that provider’s full feature set.

jlrdw's avatar

Also you could have a look at https://github.com/spatie/laravel-searchable

You could also build your own with the like clause and build a certain set of known searches, which is what I normally do. It can take a little while, but well worth it at the end.

1 like

Please or to participate in this conversation.