Getting Started with MeiliSearch: Installation, Laravel Integration, and Basic Operations
This guide introduces MeiliSearch, outlines its key features, shows how to install it, integrate it with Laravel using Scout, configure queues, define document structures, and perform basic search operations with code examples.
MeiliSearch is a fast, open‑source search engine written in Rust that supports typo‑tolerance, multi‑language indexing (including Chinese), filters, facets, geo‑search, and vector search, making it suitable for small‑to‑medium projects.
Features include sub‑50 ms query latency, low spelling error tolerance, multilingual support, highlighted results, multi‑tenant tokens, geolocation filtering, and vector search.
Installation can be done with a single command:
# Install Meilisearch
curl -L https://install.meilisearch.com | sh
# Start Meilisearch
./meilisearchMeiliSearch provides SDKs for many languages. For Laravel integration, first install the required PHP packages:
composer require meilisearch/meilisearch-php guzzlehttp/guzzle http-interop/http-factory-guzzle:^1.0
composer require meilisearch/meilisearch-php symfony/http-client nyholm/psr7:^1.0
composer require laravel/scout
composer require algolia/algoliasearch-client-phpPublish the Scout service provider and configure the queue:
php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider" 'queue' => true,
'queue' => [
'connection' => 'redis',
'queue' => 'scout',
],
SCOUT_DRIVER=meilisearch
MEILISEARCH_HOST=http://127.0.0.1:7700
MEILISEARCH_KEY=masterKeyDefine a searchable model, for example Post :
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;
class Post extends Model {
use Searchable;
}Document structures consist of objects with fields (attributes) and values. Example JSON documents for a movies index:
[
{"id":1,"title":"Diary of a Wimpy Kid: Rodrick Rules","author":"Jeff Kinney","genres":["comedy","humor"],"price":5.00},
{"id":2,"title":"Black Leopard, Red Wolf","author":"Marlon James","genres":["fantasy","drama"],"price":5.00}
]To add documents and perform a search:
<?php
use Meilisearch\Client;
$client = new Client('http://127.0.0.1:7700', 'masterKey');
$index = $client->index('movies');
$documents = [
['id'=>1,'title'=>'Carol','genres'=>['Romance, Drama']],
// ... more documents
];
$index->addDocuments($documents);
$hits = $index->search('wondre woman')->getHits();
print_r($hits);In Laravel, searching can be done via Scout:
$movies = Movies::search('Wonder Woman')->paginate(15);The article also lists common MeiliSearch operations such as creating, updating, swapping, and deleting indexes, adding or updating documents, managing tasks, and creating dumps or snapshots.
Conclusion : MeiliSearch offers a simple yet performant full‑text search solution; the guide provides essential installation and usage steps for developers integrating it into Laravel projects.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.