Repo Laravel-Meetup Mai

Search with Laravel Scout

At the Laravel DACH Meetup in May, the focus was on the simple, driver-based solution for full-text searches in Eloquent models. More about it here and in the video.

Friday, May 13, 2022

Our Meetup in May was all about search, more specifically Laravel Scout. In his talk, Jure Knezovic gave an insight into using Scout in combination with a database-driven driver and Meilisearch.

 

What Exactly Is Laravel Scout?

Scout is a driver-based solution for searching Eloquent models. Scout can be thought of as a link between Eloquent and the indexes of all searchable resources. Scout makes it easier to store these indexes in, for example, MySQL databases, Algolia, Meilisearch, or even other search index engines such as Elasticsearch.

 

Why Should You Use Scout?

Especially if you are a developer looking for an alternative to SQL queries, it is worth looking into Scout. Compared to "where like%" queries, for example, Scout is much clearer and therefore less prone to errors. The input itself is also simpler.

 

How Is Scout Installed?

Scout is installed classically via the composer:

Composer require laravel/scout Php artisan vendor:publish –provider=”Laravel/Scout/ScoutServiceProvider”

After that the drivers, keys, prefixes, etc. have to be set in the config/scout.phpand use Searchable; has to be added to the models. Then the search can start.

 

What Are the Requirements?

For the successful implementation of Scout it must be defined in advance with toSearchableArray(), which columns of the model are searchable.

 

The Use in Practice

How Laravel Scout behaves in practice with a database and Meilisearch as driver is shown in the video.

 

Meilisearch is an open source search engine that can be flexibly integrated into websites and applications. It is highly customizable and offers useful features such as the inclusion of synonyms, the exclusion of certain words or fields, and an individual typo tolerance.

This is also reflected in Jure's conclusion:

 

The database-based driver is very rudimentary but easy to link with Laravel. In comparison, Meilisearch offers much more extensive functionality, but at the same time is more trouble to install and set up.

Jure Knezovic, Developer

You don't want to miss a Meetup anymore?

Become part of our Laravel Meetup group!

join now