packagist meilisearch/meilisearch-php v2.0.0-beta.8
v2.0.0-beta.8 ๐ŸŒฑ

9 hours ago

Migration guide

If you're migrating from v1.x, read the complete migration guide.

Per-index APIs now use Index instead of Indexes

The per-index object from $client->index() / $client->getIndex() is now Meilisearch\Endpoints\Index. Metadata is lazy-loaded; fetchInfo() and fetchPrimaryKey() were removed.

Update type hints, imports, and code that fetched index metadata or assumed getIndex() made an HTTP call.

Rename Indexes to Index

// Before (v1.x)
use Meilisearch\Endpoints\Indexes;

function handle(Indexes $index): void { /* ... */ }

// After (v2.x)
use Meilisearch\Endpoints\Index;

function handle(Index $index): void { /* ... */ }

getIndex() is now lazy

// Before (v1.x) - threw ApiException immediately if the index didn't exist
$index = $client->getIndex('missing');

// After (v2.x) - the call to a getter triggers the fetch (and any exception)
$index = $client->getIndex('missing');
$index->getPrimaryKey(); // ApiException thrown here

Call getters instead of fetchInfo() / fetchPrimaryKey()

// Before (v1.x)
$index = $client->index('books');
$index->fetchInfo();
$primaryKey = $index->fetchPrimaryKey();

// After (v2.x)
$index = $client->index('books');
$primaryKey = $index->getPrimaryKey(); // loads on demand

getUid(), getCreatedAt(), getUpdatedAt() are no longer nullable

// Before (v1.x)
$date = $index->getCreatedAt();
if ($date !== null) {
    echo $date->format(DATE_ATOM);
}

// After (v2.x)
echo $index->getCreatedAt()->format(DATE_ATOM);

multiSearch() now takes MultiSearchQuery

setIndexUid() and setFederationOptions() were moved off SearchQuery and onto the new MultiSearchQuery class. SearchQuery is now only for single-index search.

Update multi-search and federation query construction.

Use MultiSearchQuery for multiSearch()

// Before (v1.x)
use Meilisearch\Contracts\SearchQuery;

$client->multiSearch([
    (new SearchQuery())->setIndexUid('books')->setQuery('prince'),
    (new SearchQuery())->setIndexUid('songs')->setQuery('be'),
]);

// After (v2.x)
use Meilisearch\Contracts\MultiSearchQuery;

$client->multiSearch([
    (new MultiSearchQuery())->setIndexUid('books')->setQuery('prince'),
    (new MultiSearchQuery())->setIndexUid('songs')->setQuery('be'),
]);

Use MultiSearchQuery for federation options

// Before (v1.x)
$query = (new SearchQuery())
    ->setIndexUid('books')
    ->setFederationOptions((new FederationOptions())->setWeight(0.5));

// After (v2.x)
$query = (new MultiSearchQuery())
    ->setIndexUid('books')
    ->setFederationOptions((new FederationOptions())->setWeight(0.5));

Index stats now return a typed IndexStats object

Index stats APIs no longer return array-based responses. They now return a typed IndexStats object.

Update code that reads index stats fields to use getter methods.

$stats = $index->stats();

// Before (v1.x)
$count = $stats['numberOfDocuments'];
$indexing = $stats['isIndexing'];
$fields = $stats['fieldDistribution'];

// After (v2.x)
$count = $stats->getNumberOfDocuments();
$indexing = $stats->isIndexing();
$fields = $stats->getFieldDistribution();

getSettings() returns plain arrays for nested settings

synonyms, typoTolerance, faceting, and embedders are now plain arrays instead of iterable setting objects, so iterator_to_array() is no longer needed.

Update code that converts nested settings to arrays.

$settings = $index->getSettings();

// Before (v1.x)
$typoTolerance = iterator_to_array($settings['typoTolerance']);
$synonyms = iterator_to_array($settings['synonyms']);

// After (v2.x)
$typoTolerance = $settings['typoTolerance'];
$synonyms = $settings['synonyms'];

Batch APIs now return typed Batch objects

Batch APIs no longer return array-based responses. They now return typed Batch objects.

Update code that reads batch fields or lists batches.

// Before (v1.x)
$batch = $client->getBatch($uid);
$uid = $batch['uid'];
$startedAt = $batch['startedAt']; // string
$total = $batch['stats']['totalNbTasks'];

// After (v2.x)
$batch = $client->getBatch($uid);
$uid = $batch->getUid();
$startedAt = $batch->getStartedAt(); // \DateTimeImmutable
$total = $batch->getStats()->getTotalNbTasks();

This also applies to $client->getBatches(). getResults() now returns an array of Batch objects.

// Before (v1.x)
$batches = $client->getBatches();
$uid = $batches->getResults()[0]['uid'];

// After (v2.x)
$batches = $client->getBatches();
$uid = $batches->getResults()[0]->getUid();

progress is a BatchProgress object while the batch is running, and null when it has finished.

// Before (v1.x)
$percent = $batch['progress']['percentage'] ?? null;

// After (v2.x)
$percent = $batch->getProgress()?->getPercentage();

๐Ÿงช Experimental

  • Breaking: Update dynamic search rules for Meilisearch v1.54 (#952) @Strift

โš ๏ธ Breaking changes

  • Separate Index endpoint and add type-safe search query DTOs (#914) @norkunas
  • Add types to Indexes stats, settings, and search (#931) @Strift
  • Typehint Batch results (#928) @Strift

๐Ÿš€ Enhancements

โš™๏ธ Maintenance/misc

  • Replace timing-bound wait() tests with HTTP-stubbed polling (#947) @Strift
  • Add a scheduled workflow to bump pinned Meilisearch versions (#951) @Strift

Thanks to @Strift, @murilolivorato and @norkunas! ๐ŸŽ‰

See full changelog: v2.0.0-beta.7...v2.0.0-beta.8

Don't miss a new meilisearch-php release

NewReleases is sending notifications on new releases.