Build Meilisearch indexes from any Craft element query, keep them current as content changes, and rebuild them with zero downtime, on a server you can host yourself to keep search costs down.
- Index entries, assets, or Commerce products from any Craft element query, and keep the documents current as elements are saved, restored, and deleted.
- Define as many indexes as your site needs, each with its own settings and its own source, including data from outside Craft such as an external product API.
- Turn one element into several documents (an article becomes one document per paragraph), or leave it out of the index.
- Reindex an element when data it includes changes (an article when its author is saved).
- Use Meilisearch's facets, filters, sorting, ranking rules, synonyms, typo tolerance, and embedders by setting them in code and sending them with one command on deploy.
- Rebuild an index with zero downtime.
- Build search pages in Twig with filters, sorting, and pagination.
You define each index in config/meilisearch-connect.php as an element query and a transformer, then run ./craft meilisearch-connect/sync/settings and ./craft meilisearch-connect/sync/all. After that, the plugin queues a sync in Craft's queue whenever an element the index covers is saved, restored, or deleted. A change appears in Meilisearch when the queue runs. A refresh builds a full copy of an index and swaps it in when the copy is complete.
<?php
use craft\elements\db\EntryQuery;
use craft\elements\Entry;
use craft\helpers\App;
use fostercommerce\meilisearch\builders\IndexBuilder;
use fostercommerce\meilisearch\builders\IndexSettingsBuilder;
return [
'meiliHostUrl' => 'http://localhost:7700',
'meiliAdminApiKey' => App::env('MEILI_ADMIN_API_KEY'),
'meiliSearchApiKey' => App::env('MEILI_SEARCH_API_KEY'),
'indices' => [
'pages' => IndexBuilder::fromSettings(
IndexSettingsBuilder::create()
->withSearchableAttributes(['title', 'body'])
->build(),
)
->withElementQuery(
static fn (): EntryQuery => Entry::find()->section('pages'),
static fn (Entry $entry): array => [
'id' => $entry->id,
'title' => $entry->title,
'body' => $entry->body,
'url' => $entry->getUrl(),
],
)
->build(),
],
];Each entry in the pages section becomes one document with the fields the transformer returns.
- PHP
^8.1 - Craft CMS
^4.6or^5.0 - Meilisearch
^1.11
composer require fostercommerce/meilisearch-connect
./craft plugin/install meilisearch-connect- Getting started, install, configure an index, and run your first search
- User guide, the Control Panel utility
- Dev guide, transformers, dependencies, custom data, and sync events
- Reference, configuration, console commands, and the class reference
- Recipes, worked examples for entries, multiple documents, dependencies, and Twig search
Proprietary
