Skip to content

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

Craft CMS plugins

Meilisearch Connect

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.

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:

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

The default auto-sync setting is on. After the first sync, the plugin keeps saved, restored, and deleted entries up to date.

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