Laravel Scout with meilisearch

Having installed MeiliSearch on windows, let’s implement Laravel Scout with MeiliSearch into an existing project:

Then publish the assets:

In the /config/scout.php alter the default driver algolia to meilisearch. Additionally add the SCOUT_DRIVER to your .env file.

Of course, we let scout use our sweet queue workers 🙂 thx to @themsaid

And finally add your master key to config file:

Next step, we add the „Searchable“ trait to the model we want to be searched. In my case it’s model called „Title“ which holds all the information of the books in our library:

Next step, we have to install the meilisearch php driver:

For the sake of completeness, here are the three keys in my .env file

Allright, so far the prerequisites.

Now let’s go on to the Laravel part of our full text search implementation.

By adding the Searchable trait Laravel Scout connects the search info by using the table name; in my case I’ll find the search results with the key „titles“ (otherwise see https://laravel.com/docs/8.x/scout#configuring-model-indexes).

By default, Laravel Scout will add all the column information to the searchable information; that’s okay. My title table only contains public information (otherwise see https://laravel.com/docs/8.x/scout#configuring-searchable-data).

And using the primary key of my title tables entries for indexing the search results is also fine for me (otherwise see https://laravel.com/docs/8.x/scout#configuring-the-model-id).

Now it’s time to import the search data for the first time. My titles table is filled with around 10 000 entries, let’s give it a try:

(my model is hided in a modules-directory – normally instead of modules/library/title it would sth like app/title or as of Laravel 8 app/models/title)

And have a look, it looks like all is working 🙂

(1) the commands output

(2) my workers dequeuing the jobs

and (3) the meilisearch console

YEAH, so now we finally can search:

And yes, it works!