Search engine on Bookshelves use laravel/scout which can use Algolia or Meilisearch to use powerful search engine. If you want to use only embeded search engine, you can just set SCOUT_DRIVER into .env to collection, less efficient than meilisearch but useful for search.


Options available: meilisearch, algolia, collection

When you use Bookshelves for development, you can set it to collection, you won't need to have engine.

Option: Meilisearch

If you want to use a more powerful engine, you can use Meilisearch, if you configure laravel/scout with meilisearch each new model will be register into Meilisearch database.


You have to execute meilisearch server available on same machine with right configuration.

# default configuration for meilisearch

Install Meilisearch

These commands have to be used as root user.

These options are available for Linux or MacOS, for Windows, you can use WSL to install meilisearch like on Linux but you can also download latest binary to execute server.

curl -L | sh
mv ./meilisearch /usr/bin/
brew update
brew install meilisearch
echo "deb [trusted=yes] /" > /etc/apt/sources.list.d/fury.list
apt update
apt install meilisearch-http

Execute server


On production

On production you have to setup a service.

sudo vim /etc/systemd/system/meilisearch.service

You can change Y0urVery-S3cureAp1K3y with your master key (you will add it to .env into MEILISEARCH_KEY).


ExecStart=/usr/bin/meilisearch --http-addr --env production --master-key Y0urVery-S3cureAp1K3y


Now you can enable service.

sudo systemctl enable meilisearch
sudo systemctl start meilisearch

Check if it works

sudo systemctl status meilisearch

Add NGINX domain

You can have more information on Meilisearch documentation.

server {
  listen 80;
  listen [::]:80;

  location / {

  access_log /var/log/nginx/meilisearch.access.log;
  error_log /var/log/nginx/meilisearch.error.log;

Now Meilisearch is available on You will have to update .env on MEILISEARCH_HOST with new URL.

Import models

You can import Book, Author and Serie with Bookshelves command.

php artisan bookshelves:scout

If you want to reset all models of Bookshelves, you can flush existing indexes with -f option.

php artisan bookshelves:scout -f

Test search: Meilisearch

If you have an meilisearch instance, you can check it to (default configuration). If importation works, you will see three indexes for Book, Author and Serie and you can search into each index.

All fields you can see on each index is available for search.

Example: on Book, if title is available, Meilisearch will allow you to search on it, if you want to add description you can add into Book model toSearchableArray method, check Laravel documentation.


Into a controller, you can search with search method

Book::search('any search')->get();

Customize fields

Meilisearch check all fields but you can limit it with toSearchableArray

public function toSearchableArray()
  return [
    'id' => $this->id,
    'title' => $this->title,
    'date' => $this->date,
    'author' => $this->authors_names,
    'created_at' => $this->created_at,
    'updated_at' => $this->updated_at,

And execute again scout command with php artisan booksheves:scout -f

With API v1

You can search any entity on http://localhost:8000/api/v1/search like http://localhost:8000/api/v1/search?q=any%20title

Route::prefix('search')->group(function () {
  Route::get('/', [SearchController::class, 'index'])->name('');

You can check SearchController.php to know how search engine works, under the hood you can check SearchEngineService.php.

public function index(Request $request)
  $q = $request->input('q');
  $types = $request->input('types');
  if ($types) {
    $types = explode(',', $types);

  if ($q) {
    $engine = SearchEngineService::create($q, $types);

    return response()->json([
      'data' => [
        'count' => $engine->results_count,
        'type' => $engine->search_type,
        'relevant' => [
          'authors' => $engine->authors_relevant,
          'series' => $engine->series_relevant,
          'books' => $engine->books_relevant,
        'other' => [
          'authors' => $engine->authors_other,
          'series' => $engine->series_other,
          'books' => $engine->books_other,


No indexes on Meilisearch

If you don't see indexes on, it may be cause by cache.

php artisan cache:clear
php artisan bookshelves:scout -f

Version file is missing

Version file is missing or the previous MeiliSearch engine version was below 0.24.0. Use a dump to update MeiliSearch

When you update Meilisearch, you can have this error, you have to remove

If you delete, all indexes will be deleted.

sudo rm -rf /

Now you have to restart meilisearch.

sudo service meilisearch restart

Check if service works.

sudo service meilisearch status
Edit this page on GitHub Updated at Tue, Apr 12, 2022