
What Do You Mean By Full-Text Search?
According to Wikipedia, Full-Text Search is a technique of searching a single computer-stored document or a collection in the full-text database. Here, the search engine inspects all the words stored in a particular document.
According to Techopedia, Full-Text Search is a comprehensive method that compares every word of the search request against every word written in report or database.
The Full-Text Search allows users to navigate content-rich websites with ease.
- Search on multiple columns at one go.
- Sort the results.
- Optimize the query performance.
- Utilize the advanced search pattern.
- Use your MySQL server.
So far, we have analyzed the basics of Full-Text Search. Now, we’re going to provide you with a step-by-step guide on setting up a Full-Text Search in Laravel web app.
So, let’s get this started right now.!
- <iframe src="https://giphy.com/embed/26h0poAzDM5h8gHWE" width="480" height="263" frameBorder="0" class="giphy-embed" allowFullScreen>
- </iframe>
- <p><a href="https://giphy.com/gifs/bbmas-bbmas-2016-26h0poAzDM5h8gHWE">via GIPHY</a></p>
Step-By-Step Guide To Set Up A Full-Text Search In Laravel
- Step 1: Understanding Scout Library
- Step 2: Installing Scout & Algolia
- Step 3: Making Models Indexable & Searchable
- Step 4: Implementing Full-Text Search
Step 1 - Understanding Scout Library
For setting up a Full-Text Search in Laravel, we’re going to use Scout. It’s a library which makes the implementation process very easy. So, let’s understand about that in detail.
As per the official documentation, Laravel Scout is a driver-based & straightforward solution. It adds Full-Text Search to Eloquent Models. The library makes use of model observers. The reason for that is to keep search index in sync with Eloquent records.
Laravel Scout's prime job is to look after the index changes. Now, the question is, where will the shift happen in an index? It depends on the type of driver that you will use with Scout.
The Scout library assists Algolia. It’s a cloud-based search engine API used in conjunction with Scout for Full-Text Search implementation.
In this section, we’re going to provide the installation procedure for Scout & Algolia. First of all, you need to manage the server configurations.
For that purpose, installing all the dependencies for the Scout library is essential. The reason behind that is, it will allow Scout library to work with your existing Laravel application.
To install the Scout library using the composer, use the following code:
- $composer require laravel/scout
Once you execute this code, the Scout library will get installed. After completing the installation part, the next step is to inform the Laravel about that.
For that purpose, we’re going to make use of Service Providers. If you’re someone who is working as a Laravel Developer, then you must know about this concept.
Service Providers allow you to configure any new service in the existing application. So, whenever you want to add any new service in Laravel, add an associated service provider entry in config/app.php
Here, you need to add ScoutServiceProvider to the list of service providers in config/app.php as shown in the coding snippet below,
- 'providers' => [
- /*
- * Application Service Providers...
- */
- App\Providers\AppServiceProvider::class,
- App\Providers\AuthServiceProvider::class,
- App\Providers\BroadcastServiceProvider::class,
- App\Providers\EventServiceProvider::class,
- App\Providers\RouteServiceProvider::class,
- Laravel\Scout\ScoutServiceProvider::class,
- ],
After using this code, Laravel will surely become aware of ScoutServiceProvider.
There is a configuration file associated with the Scout library. With the help of that, you can set API credentials. Now, publish the assets that the Scout library provides.
- $ php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"
- Copied File [/vendor/laravel/scout/config/scout.php] To [/config/scout.php]
- Publishing complete.
The next thing you need to do is to create an account with Algolia. It will allow us to get access to the API credentials. For that purpose, move to the official website.


After getting the details about API, it's time to configure the settings in a config/app.php file.
- <?php
- return [
- /*
- |--------------------------------------------------------------------------
- | Default Search Engine
- |--------------------------------------------------------------------------
- */
- 'driver' => env('SCOUT_DRIVER', 'algolia'),
- /*
- |--------------------------------------------------------------------------
- | Index Prefix
- |--------------------------------------------------------------------------
- */
- 'prefix' => env('SCOUT_PREFIX', ''),
- /*
- |--------------------------------------------------------------------------
- | Queue Data Syncing
- |--------------------------------------------------------------------------
- */
- 'queue' => env('SCOUT_QUEUE', false),
- /*
- |--------------------------------------------------------------------------
- | Chunk Sizes
- |--------------------------------------------------------------------------
- */
- 'chunk' => [
- 'searchable' => 500,
- 'unsearchable' => 500,
- ],
- /*
- |--------------------------------------------------------------------------
- | Soft Deletes
- |--------------------------------------------------------------------------
- */
- 'soft_delete' => false,
- /*
- |--------------------------------------------------------------------------
- | Algolia Configuration
- |--------------------------------------------------------------------------
- */
- 'algolia' => [
- 'id' => env('ALGOLIA_APP_ID', 'STQK4DEGMA'),
- 'secret' => env('ALGOLIA_SECRET', '6ef572194f70201ed7ad102cc9f90e05'),
- ],
- ];

Kean SargentPosted Mar 15, 2022, 5:04 PM
Thank you for the brilliant job, Harikrishna!
Vijay PatelPosted Jul 2, 2020, 12:58 AM
Thanks for an excellent article.
Laxmidhar SahooPosted Apr 9, 2019, 12:39 AM
Thanks for a usefull article
Harikrishna KundariyaPosted Mar 27, 2019, 11:36 PM
Md Sarfaraj Thanks For Your valuable Feedback
Md SarfarajPosted Mar 27, 2019, 9:31 AM
Nice blog, Harikrishna Kundariya