Skip to content

Commerce Foundations is our pre-built Craft Commerce store. See what it includes

Craft CMS plugins

Meilisearch Connect

Meilisearch Connect enables seamless data synchronization between Craft CMS and Meilisearch.

Recipe: index entries

This index sends news entries to a Meilisearch index named news.

<?php

use craft\elements\Entry;
use craft\elements\db\EntryQuery;
use fostercommerce\meilisearch\builders\IndexBuilder;
use fostercommerce\meilisearch\builders\IndexSettingsBuilder;

return [
    'meiliHostUrl' => 'http://localhost:7700',
    'meiliAdminApiKey' => '<Meilisearch Admin Key>',
    'meiliSearchApiKey' => '<Meilisearch Search Key>',
    'indices' => [
        'news' => IndexBuilder::fromSettings(
            IndexSettingsBuilder::create()
                ->withSearchableAttributes(['title', 'summary', 'body'])
                ->withFilterableAttributes(['category'])
                ->withSortableAttributes(['postDate'])
                ->build(),
        )
            ->withElementQuery(
                static fn (): EntryQuery => Entry::find()->section('news'),
                static fn (Entry $entry): array => [
                    'id' => $entry->id,
                    'title' => $entry->title,
                    'summary' => $entry->summary,
                    'body' => $entry->body,
                    'category' => $entry->category->one()?->title,
                    'postDate' => $entry->postDate?->format(DATE_ATOM),
                    'url' => $entry->getUrl(),
                ],
            )
            ->build(),
    ],
];

Then run:

php craft meilisearch-connect/sync/settings
php craft meilisearch-connect/sync/index news

The default auto-sync setting is on. Saved, restored, and deleted entries are kept up to date after the first sync.

We can take it from here.

We take on the Craft and Craft Commerce sites you built, so you can get back to building. Introduce a client who signs a management contract and you get a $3,000 partnership fee.

How the Dev Partnership Program works
See if we’re a fit