meilisearch/meilisearch-php
Official Meilisearch PHP SDK: a fast, easy API client to index documents, manage settings, and run searches with Meilisearch or Meilisearch Cloud. Supports popular HTTP clients and customizable transport.
[!NOTE] This replaces the incorrect
v2.0.0-beta.4release tagged from the wrong branch.
$client->getTasks() and $index->getTasks() now return a TaskResults object.
// Before (v1.x)
$tasks = $client->getTasks();
$results = $tasks['results']; // Accessing as array
// After (v2.x)
$tasks = $client->getTasks(); // Returns TaskResults
$results = $tasks->getResults(); // Returns an array of Task objects
Additionally
all() method now returns an array of Task objects.TaskResults class is now finalTask before passing to TasksResults (#864) @norkunasTask and implement ArrayAccess (backward compatibility) (#863) @norkunasThanks to @Strift, @norkunas and dependabot[bot]! 🎉
See full changelog: https://github.com/meilisearch/meilisearch-php/compare/v2.0.0-beta.3...v2.0.0-beta.5
[!WARNING] This release was incorrectly tagged from the wrong branch.
Please usev2.0.0-beta.5instead.
The custom $message property has been removed from custom exceptions. Use the getMessage() method instead:
try {
// ...
} catch (\Meilisearch\Exceptions\ApiException $e) {
// Before (v1.x)
echo $e->message;
// After (v2.x)
echo $e->getMessage();
}
Also:
rethrowWithHint static method now returns a \RuntimeException instead of a generic \Exception.Thanks to @Strift and @norkunas! 🎉
See full changelog: https://github.com/meilisearch/meilisearch-php/compare/v2.0.0-beta.2...v2.0.0-beta.3
Stats object$stats = $client->stats();
// Before (v1.x) - accessing stats as array
$databaseSize = $response['databaseSize'];
$usedDatabaseSize = $response['usedDatabaseSize'];
// etc...
// After (v2.x) - use getter methods
$databaseSize = $stats->getDatabaseSize();
$usedDatabaseSize = $stats->getUsedDatabaseSize();
Version object$version = $client->version();
// Before (v1.x) - access as array
$commitSha = $version['commitSha'];
$commitDate = $version['commitDate']; // String
$pkgVersion = $version['pkgVersion'];
// After (v2.x) - use getter methods
$commitSha = $version->getCommitSha();
$commitDate = $version->getCommitDate(); // \DateTimeImmutable
$pkgVersion = $version->getPkgVersion();
MeiliSearch namespaceWe removed MeiliSearch (capital S) namespace.
// Before (v1.x) - MeiliSearch with capital S
use MeiliSearch\Client;
// After (v2.x) - Meilisearch without capital S
use Meilisearch\Client;
Indexes::parseDate() public methodThis only affects you if you were using this utility method directly.
// Before (v1.x) - If you used this method in your code
$dateTime = \Meilisearch\Endpoints\Indexes::parseDate('2021-01-01T01:23:45.123456Z');
// After (v2.x) - Use native PHP instead
$dateTime = new \DateTimeImmutable('2021-01-01T01:23:45.123456Z');
Stats object (#823) @norkunasVersion object (#821) @norkunasThanks to @Strift, @bpolaszek, @dependabot[bot], @norkunas, @tacman, and @walkwizus! 🎉
See full changelog: https://github.com/meilisearch/meilisearch-php/compare/v2.0.0-beta.1...v2.0.0-beta.2
While we recommend against production usage due to breaking changes, the code is stable. Please consider whether you can afford the potential upcoming breaking changes before upgrading.
This introduces two changes:
wait(int $timeoutInMs = 5000, int $intervalInMs = 50): Task methodAwaiting tasks:
// Before
$promise = $this->client->createIndex('new-index', ['primaryKey' => 'objectID']);
$this->index->waitForTask($promise['taskUid']);
// After
$this->client->createIndex('new-index', ['primaryKey' => 'objectID'])->wait();
Asserting task status:
// Before
$task = $this->client->getTask($taskUid);
if ($task['status'] === 'succeeded') {
// do something
}
// After
if ($task->getStatus() === TaskStatus::Succeeded) {
// do something
}
Asserting task types:
// Before
$task = $this->client->getTask($taskUid);
if ($task['type'] === 'indexCreation') {
// do something
}
// After
$task = $this->client->getTask($taskUid);
if ($task->getType() === TaskType::IndexCreation) {
// do something
}
Before: catching SDK-specific JSON exceptions
<?php
try {
$client->index('books')->addDocuments([["title" => "\xB1\x31"]]);
} catch (JsonEncodingException | JsonDecodingException $e) {
// handle JSON errors
}
After: catching native PHP JsonException
<?php
try {
$client->index('books')->addDocuments([["title" => "\xB1\x31"]]);
} catch (\JsonException $e) {
// handle JSON errors
}
documents endpoint (#779) @bpolaszekphp-version in matrix (#792) @StriftThanks to @Strift, @bpolaszek, and @norkunas! 🎉
See full changelog: https://github.com/meilisearch/meilisearch-php/compare/v1.16.0...v2.0.0-beta.1
This PR adds support for sorting to the documents endpoint.
Thanks to @Strift, and dependabot[bot]! 🎉
See full changelog: https://github.com/meilisearch/meilisearch-php/compare/v1.16.0...v1.16.1
This release makes the SDK compatible with features release in Meilisearch 1.16.
retrieveVectors (#777) @bpolaszekThanks again to @Strift, @bpolaszek, @brunoocasali, and @norkunas! 🎉
This version introduces features released in Meilisearch v1.15.0.
disableOnNumbers field to typo tolerance settings (#753) @StriftThanks again to @Strift! 🎉
This version introduces features released on Meilisearch v1.13.0 🎉 Check out the changelog of Meilisearch v1.13.0 for more information on the changes.
Thanks again to @Strift! 🎉
This version introduces features released on Meilisearch v1.12.0 🎉
Check out the Meilisearch v1.12.0 changelog for more information.
Introducing new methods to get one or several batches, respectively getBatch() and getBatches(). A batch is a set of tasks processed together.
The TaskQuery class now has a setReverse() method to retrieve tasks in reverse chronological order.
client->getTasks((new TasksQuery())->setReverse(true));
Index settings now allow disabling prefix search and facet search. They're both enabled by default. The SDK now comes with dedicated methods to configure these settings.
// disable prefix search
$index->updatePrefixSearch('disabled');
// reset prefix search settings
$index->resetPrefixSearch();
// disable facet search
$index->updateFacetSearch(false);
// reset facet search settings
$index->resetFacetSearch();
hitsCount always the number of hits (and not totalHits value) (https://github.com/meilisearch/meilisearch-php/pull/701) @johnnynotsoluckyThanks again to @aivchen, @johnnynotsolucky, @norkunas, @mdubus and @Strift! 🎉
This version introduces features released on Meilisearch v1.11.0 🎉 Check out the changelog of Meilisearch v1.11.0 for more information on the changes.
multiSearch (#683) @ManyTheFish & @norkunasrankingScoreThreshold to SimilarDocumentsQuery (#675) @norkunasThanks again to @ManyTheFish, @grizzm0, @apozeus and @norkunas! 🎉
Thanks again to @brunoocasali, and @norkunas! 🎉
This version introduces features released on Meilisearch v1.9.0 🎉 Check out the changelog of Meilisearch v1.9.0 for more information on the changes.
$client->index('INDEX_NAME')->search('badman', [
'rankingScoreThreshold' => 0.2
]);
$similarQuery = new SimilarDocumentsQuery('TARGET_DOCUMENT_ID');
$client->index('INDEX_NAME')->getSimilar($similarQuery);
setRetrieveVectors method to SimilarDocumentsQuerysetRetrieveVectors method to DocumentsQuery$client->index('products')->updateFilterableAttributes(['product_id', 'sku', 'url']);
Thanks again to @Koopzington, @ManyTheFish, @curquiza, and @the-sinner! 🎉
This version introduces features released on Meilisearch v1.8.0 🎉 Check out the changelog of Meilisearch v1.8.0 for more information on the changes.
searchCutoffMs (https://github.com/meilisearch/meilisearch-php/pull/636) @brunoocasali$client->index('books')->getSearchCutoffMs();
$client->index('books')->updateSearchCutoffMs(150);
$client->index('books')->resetSearchCutoffMs();
getSemanticHitCount() method to retrieve how many results were found because of the semantic query. https://github.com/meilisearch/meilisearch-php/pull/639 @brunoocasaliThanks again to @brunoocasali, @curquiza, @guimachiavelli, and @norkunas! 🎉
This version introduces features released on Meilisearch v1.7.0 :tada: Check out the changelog of Meilisearch v1.7.0 for more information on the changes.
scoreDetails feature is not experimental anymore. You can directly use showRankingScoreDetails during a search without activating the experimental feature 🎉proximityPrecision (https://github.com/meilisearch/meilisearch-php/pull/606) brunoocasali$client->index('books')->getProximityPrecision();
$client->index('books')->updateProximityPrecision('byAttribute');
$client->index('books')->resetProximityPrecision();
⚠️ This is about an experimental feature of Meilisearch. Activate the vectorStore experimental feature to use it
embedders settings & Add support for the hybrid parameter during search (https://github.com/meilisearch/meilisearch-php/pull/608) brunoocasali$client->index('books')->getEmbedders();
$client->index('books')->updateEmbedders(['default' => ['source' => 'userProvided', 'dimensions' => 1]]);
$client->index('books')->resetEmbedders();
[@throws](https://github.com/throws) in HandlesTasks delegate (#599) @norkunasThanks again to @norkunas, @brunoocasali! 🎉
This version introduces features released on Meilisearch v1.5.0 :tada: Check out the changelog of Meilisearch v1.5.0 for more information on the changes.
⚠️ If you want to adopt new features of this release, update the Meilisearch server to the appropriate version.
createSnapshot() to trigger snapshot creation. Similar to the already existing createDump() for dumps (#587) @brunoocasaliThanks again to @mmachatschek! 🎉
This version introduces features released on Meilisearch v1.4.0 :tada: Check out the changelog of Meilisearch v1.4.0 for more information on the changes.
⚠️ If you want to adopt new features of this release, update the Meilisearch server to the according version.
dictionary (#574) @alallema$index->getDictionary();
$index->updateDictionary(['J. R. R.', 'W. E. B.']);
$index->resetDictionary();
separator-tokens (#574) @alallema$index->getSeparatorTokens();
$index->updateSeparatorTokens(['|', '…']);
$index->resetSeparatorTokens();
non-separator-tokens (#574) @alallema$index->getNonSeparatorTokens();
$index->updateNonSeparatorTokens(['@', '#']);
$index->resetNonSeparatorTokens();
A bug fix in Meilisearch v1.4.0 introduces a breaking change in the filter usage. It only concerns users using the filter search parameter with \.
Explanation and change to apply are detailed in the Meilisearch v1.4.0
Thanks again to @alallema, @brunoocasali, @curquiza, @dependabot, @dependabot[bot], @meili-bors[bot], and @norkunas! 🎉
This version introduces features released on Meilisearch v1.3.0 :tada: Check out the changelog of Meilisearch v1.3.0 for more information on the changes.
⚠️ If you want to adopt new features of this release, update the Meilisearch server to the according version.
setShowRankingScoreDetails and search(['showRankingScoreDetails' => boolean]) to show the scores of each relevant document returned in the search.setVector and search(['vector' => [...]]) to enable vector search capabilities.setAttributesToSearchOn and search(['attributesToSearchOn' => [...]])index->facetSearch(FacetSearchQuery params) to search only in facets.⚠️ The EXPERIMENTAL features are not covered by semver. To explicitly opt-in, check this guide.
Thanks again to @94noni, @Strift, @alallema, @brunoocasali, @norkunas and @stloyd! 🎉
getDocuments with filters and fields being set in DocumentsQuery (#523) @panzer-punkThanks again to @justkahdri, @panzer-punk! 🎉
This version introduces features released on Meilisearch v1.2.0 :tada: Check out the changelog of Meilisearch v1.2.0 for more information on the changes. ⚠️ If you want to adopt new features of this release, update the Meilisearch server to the according version.
The method deleteDocuments() now supports a different behavior. This method could take an array containing a filter key with the filter value, which will filter and delete the documents. #509 @brunoocasali
⚠️ You must configure the attributes you want to filter using the Index\filterableAttributes().
⚠️ Remember to update your Meilisearch server to v1.2.0 or newer before adopting it.
Still, even being supported, the ability to receive only a list of ids is deprecated, and it will be removed in meilisearch-php v2
Add the ability to setFilter in the DocumentsQuery. When a query with a filter is sent to getDocuments(DocumentsQuery $query) it will filter the documents similar to the search method. See the docs on how to use filters. #510 @brunoocasali
⚠️ You must configure the attributes you want to filter using the Index\filterableAttributes().
⚠️ Remember to update your Meilisearch server to v1.2.0 or newer before adopting it.
Thanks again to @brunoocasali, @tacman, @norkunas! 🎉
This version introduces features released on Meilisearch v1.1.0 :tada: Check out the changelog of Meilisearch v1.1.0 for more information on the changes. If you want to adopt new features of this release, update the Meilisearch server to the according version.
addDocumentsCsv, addDocumentsCsvInBatches, and updateDocumentsCsvInBatches. This argument allows you to customize the separator character in your csv file. (#480) @brunoocasalifacetStats on SearchResult (#487) @brunoocasali.$client->multiSearch() method to execute multiple search requests simultaneously with different configurations. (#481) @brunoocasali
Introduce SearchQuery builder class to build the search requests used in the multiSearch.
Usage example:
$this->client->multiSearch([
(new SearchQuery())->setIndexUid('books')
->setQuery('princ')
->setSort(['author:desc']),
(new SearchQuery())->setIndexUid('movies')
->setQuery('be')
->setHitsPerPage(4)
->setFilter(['duration-float > 3']),
]);
SearchQuery was not meant to be used if the regular $index->search() requests (yet).This version makes this package compatible with Meilisearch v1.0.0 :tada: Check out the changelog of Meilisearch v1.0.0 for more information on the changes.
Endpoints/Indexes date attributes $createdAt and $updatedAt are DateTime now instead of string. (#457) @brunoocasali
getCreatedAtString and getUpdatedAtString functions.canceledBy/setCanceledBy in TasksQuery (#454) @brunoocasalinext attribute and setNext from TasksQuery. (#454) @brunoocasalinext attribute and setNext from DeleteTasksQuery. (#454) @brunoocasalinext, canceledBy attributes and setNext, setCanceledBy from CancelTasksQuery. (#454) @brunoocasalideleteAllIndexes, since they don't really delete all the indexes but only the first page. (#454) @brunoocasaligetAllRawIndexes function. (#454) @brunoocasaligetAllIndexes to getIndexes. (#454) @brunoocasalisrc/Endpoints/Delegates. (#455) @brunoocasali
Meilisearch\Delegates\HandlesIndex to Meilisearch\Endpoints\Delegates\HandlesIndexMeilisearch\Delegates\HandlesSystem to Meilisearch\Endpoints\Delegates\HandlesSystemMeilisearch\Delegates\TasksQueryTrait to Meilisearch\Endpoints\Delegates\TasksQueryTraitThanks again to @brunoocasali and @norkunas! 🎉
⚠️ This release has nothing new, and it is just a tag to mark the previous release v0.26.1 as breaking, so v0.27.0.
You should be careful because every occurrence of MeiliSearch, even in the file names were changed to Meilisearch.
More details in the comments section here and here.
Original changelog from v0.26.1:
MeiliSearch to Meilisearch (#431) @mmachatschek⚠️ If you handle ::class directly, a change is required, as pointed out https://github.com/meilisearch/meilisearch-php/pull/431#issuecomment-1365760201
Thanks again to @brunoocasali and @mmachatschek! 🎉
MeiliSearch to Meilisearch (#431) @mmachatschek⚠️ If you handle ::class directly, a change is required, as pointed out https://github.com/meilisearch/meilisearch-php/pull/431#issuecomment-1365760201
Thanks again to @brunoocasali and @mmachatschek! 🎉
How can I help you explore Laravel packages today?