In this episode, we start tackling the topic of searching discussions in our Laravel app. The focus here is all about getting our discussions indexed, which basically means preparing them so they can be searched later. We set things up so both our existing and any new discussions will show up when we search.
To make this happen, we use Laravel Scout—the built-in package that makes it easy to connect Laravel models to different search engines. We specifically use MeiliSearch for this episode because it’s free, easy to run locally, and perfect for development. (Later on, it’s simple to swap search providers if you want.)
We go step by step through installing Laravel Scout, configuring it, and then installing MeiliSearch as our driver. There’s a quick walkthrough on running MeiliSearch on your computer and making sure it’s set up in your .env
appropriately. We even cover adding data.ms
to your .gitignore
so you don’t push search data to version control.
Next, we make our Discussion
model searchable using a trait and customize what fields should be indexed (so we don’t store everything—just the title and ID). Once that’s set up, we use the Scout import command to index all our existing discussions and check the results in the MeiliSearch dashboard.
Finally, we talk about how new discussions are automatically indexed and also automatically removed if deleted—all handled by Scout with just that one trait!
By the end of this episode, our discussions are all indexed and ready, laying the groundwork for building out the actual search functionality in the next installment.