class MeilisearchEngine extends Engine implements UpdatesIndexSettings

Meilisearch search engine implementation.

Provides full-text search using Meilisearch as the backend.

Methods

void
update(Collection $models)

Update the given models in the search index.

void
delete(Collection $models)

Remove the given models from the search index.

mixed
search(Builder $builder)

Perform a search against the engine.

mixed
paginate(Builder $builder, int $perPage, int $page)

Perform a paginated search against the engine.

mapIds(mixed $results)

Pluck and return the primary keys of the given results.

map(Builder $builder, mixed $results, Model $model)

Map the given results to instances of the given model.

lazyMap(Builder $builder, mixed $results, Model $model)

Map the given results to instances of the given model via a lazy collection.

int
getTotalCount(mixed $results)

Get the total count from a raw result returned by the engine.

void
flush(Model $model)

Flush all of the model's records from the engine.

mixed
createIndex(string $name, array $options = [])

Create a search index.

mixed
deleteIndex(string $name)

Delete a search index.

mapIdsFrom(mixed $results, string $key)

Pluck the given results with the given primary key name.

keys(Builder $builder)

Get the results of the query as a Collection of primary keys.

get(Builder $builder)

Get the results of the given query mapped onto models.

from  Engine
cursor(Builder $builder)

Get a lazy collection for the given query mapped onto models.

from  Engine
__construct(Client $meilisearch, bool $softDelete = false)

Create a new MeilisearchEngine instance.

mixed
performSearch(Builder $builder, array $searchParams = [])

Perform the given search on the engine.

string
filters(Builder $builder)

Get the filter string for the query.

array
buildSortFromOrderByClauses(Builder $builder)

Get the sort array for the query.

void
updateIndexSettings(string $name, array $settings = [])

Update the index settings for the given index.

array
configureSoftDeleteFilter(array $settings = [])

Configure the soft delete filter within the given settings.

array
deleteAllIndexes(string|null $prefix = null)

Delete all search indexes, optionally scoped by uid prefix.

string
generateTenantToken(array $searchRules, string|null $apiKeyUid = null, DateTimeImmutable|null $expiresAt = null)

Generate a tenant token for frontend direct search.

string
getDefaultApiKeyUid()

Get the default API key UID for tenant token generation.

bool
usesSoftDelete(Model $model)

Determine if the given model uses soft deletes.

Client
getMeilisearchClient()

Get the underlying Meilisearch client.

mixed
__call(string $method, array $parameters)

Dynamically call the Meilisearch client instance.

Details

at line 45
void update(Collection $models)

Update the given models in the search index.

Parameters

Collection $models

Return Value

void

Exceptions

ApiException

at line 87
void delete(Collection $models)

Remove the given models from the search index.

Parameters

Collection $models

Return Value

void

Perform a search against the engine.

Parameters

Builder $builder

Return Value

mixed

at line 117
mixed paginate(Builder $builder, int $perPage, int $page)

Perform a paginated search against the engine.

Parameters

Builder $builder
int $perPage
int $page

Return Value

mixed

at line 219
Collection mapIds(mixed $results)

Pluck and return the primary keys of the given results.

Parameters

mixed $results

Return Value

Collection

at line 256
Collection map(Builder $builder, mixed $results, Model $model)

Map the given results to instances of the given model.

Parameters

Builder $builder
mixed $results
Model $model

Return Value

Collection

at line 298
LazyCollection lazyMap(Builder $builder, mixed $results, Model $model)

Map the given results to instances of the given model via a lazy collection.

Parameters

Builder $builder
mixed $results
Model $model

Return Value

LazyCollection

at line 336
int getTotalCount(mixed $results)

Get the total count from a raw result returned by the engine.

Parameters

mixed $results

Return Value

int

at line 346
void flush(Model $model)

Flush all of the model's records from the engine.

Parameters

Model $model

Return Value

void

at line 358
mixed createIndex(string $name, array $options = [])

Create a search index.

Parameters

string $name
array $options

Return Value

mixed

Exceptions

ApiException

at line 404
mixed deleteIndex(string $name)

Delete a search index.

Parameters

string $name

Return Value

mixed

Exceptions

ApiException

at line 234
Collection mapIdsFrom(mixed $results, string $key)

Pluck the given results with the given primary key name.

Parameters

mixed $results
string $key

Return Value

Collection

at line 244
Collection keys(Builder $builder)

Get the results of the query as a Collection of primary keys.

Parameters

Builder $builder

Return Value

Collection

in Engine at line 106
Collection get(Builder $builder)

Get the results of the given query mapped onto models.

Parameters

Builder $builder

Return Value

Collection

in Engine at line 118
LazyCollection cursor(Builder $builder)

Get a lazy collection for the given query mapped onto models.

Parameters

Builder $builder

Return Value

LazyCollection

at line 33
__construct(Client $meilisearch, bool $softDelete = false)

Create a new MeilisearchEngine instance.

Parameters

Client $meilisearch
bool $softDelete

at line 130
protected mixed performSearch(Builder $builder, array $searchParams = [])

Perform the given search on the engine.

Parameters

Builder $builder
array $searchParams

Return Value

mixed

at line 160
protected string filters(Builder $builder)

Get the filter string for the query.

Parameters

Builder $builder

Return Value

string

at line 209
protected array buildSortFromOrderByClauses(Builder $builder)

Get the sort array for the query.

Parameters

Builder $builder

Return Value

array

at line 376
void updateIndexSettings(string $name, array $settings = [])

Update the index settings for the given index.

Parameters

string $name
array $settings

Return Value

void

at line 392
array configureSoftDeleteFilter(array $settings = [])

Configure the soft delete filter within the given settings.

Parameters

array $settings

Return Value

array

at line 419
array deleteAllIndexes(string|null $prefix = null)

Delete all search indexes, optionally scoped by uid prefix.

When $prefix is non-empty, only indexes whose uid starts with $prefix are deleted. When $prefix is null (or empty string, which str_starts_with matches against every string), every index on the Meilisearch server is deleted.

Parameters

string|null $prefix

Return Value

array

at line 455
string generateTenantToken(array $searchRules, string|null $apiKeyUid = null, DateTimeImmutable|null $expiresAt = null)

Generate a tenant token for frontend direct search.

Tenant tokens allow secure, scoped searches directly from the frontend without exposing the admin API key. All tenants share a single index, with data isolation enforced at query time via embedded filters.

Parameters

array $searchRules

Rules per index

string|null $apiKeyUid
DateTimeImmutable|null $expiresAt

Return Value

string

See also

https://www.meilisearch.com/blog/multi-tenancy-guide

at line 472
protected string getDefaultApiKeyUid()

Get the default API key UID for tenant token generation.

Return Value

string

at line 494
protected bool usesSoftDelete(Model $model)

Determine if the given model uses soft deletes.

Parameters

Model $model

Return Value

bool

at line 502
Client getMeilisearchClient()

Get the underlying Meilisearch client.

Return Value

Client

at line 510
mixed __call(string $method, array $parameters)

Dynamically call the Meilisearch client instance.

Parameters

string $method
array $parameters

Return Value

mixed