meiji / pimcore-meilisearch-bundle
Pimcore Meilisearch Bundle
v0.2.2
2024-11-14 06:17 UTC
Requires
- php: ~8.1.0 || ~8.2.0 || ~8.3.0
- meilisearch/meilisearch-php: ^v1.9
- nyholm/psr7: ^1.8
- pimcore/pimcore: ^11.1
- symfony/http-client: ^7.1
README
Add Meilisearch API wrapper and data synchronization for Pimcore
To star using bundle you must set Mailisearch instance credentials, upgrade specify model (extend with provided interface) and apply index synchronisation:
meilisearch:index-sync
- to sync search index configuration;meilisearch:document-sync
- to sync all objects of implementing classes, optional argument "Element batch count" (default: 1000).
Bundle automaticaly add, update and delete specular document of DataObject.
Installation
- On your Pimcore 11 root project
$ composer require meiji/pimcore-meilisearch-bundle
- Set environment variables (in
.env
for ex.)
MEILISEARCH_URL=http://127.0.0.1:7700
MEILISEARCH_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
MEILISEARCH_INDEX_PREPEND=myapp_
- Register bundle in
config/bundles.php
return [
// ... Other bundles ...
Meiji\MeilisearchBundle\MeilisearchBundle::class => ['all' => true],
];
Configure model
- Add to DataObject implementation of
\Meiji\MeilisearchBundle\Model\DocumentInterface
via UI declaration, or code
use Meiji\MeilisearchBundle\Model\DocumentInterface as MeilisearchDocumentInterface;
// ...
class Product extends \Pimcore\Model\DataObject\Product implements MeilisearchDocumentInterface
{
// ...
- Release interface functions
// Index UID of DataObject model. Keep in mind usable `prefix`, that will autoprepend to this result string
public static function getMeilisearchIndexUid(): string;
// Index Primary Key of DataObject index documents
public static function getMeilisearchIndexPrimaryKey(): string;
// Next code show example index configuration with default values. You can use this values or configured for your own rules
// @see official docs [settings](https://www.meilisearch.com/docs/reference/api/settings)
public static function getMeilisearchIndexDisplayedAttributes() : array
{
return ['*'];
}
public static function getMeilisearchIndexFilterableAttributes() : array
{
return [];
}
public static function getMeilisearchIndexSearchableAttributes() : array
{
return ['*'];
}
public static function getMeilisearchIndexSortableAttributes() : array
{
return [];
}
public function getMeilisearchIndexDistinctAttribute() : ?string
{
return null;
}
public static function getMeilisearchIndexTypoTolerance() : array
{
return [
"minWordSizeForTypos" => [
"oneTypo" => 5,
"twoTypos" => 9
],
"disableOnAttributes" => [
]
];
}
public static function getMeilisearchPagination() : array
{
return [
"maxTotalHits" => 1000
];
}
public static function getMeilisearchPagination() : array
{
return [
"words",
"typo",
"proximity",
"attribute",
"sort",
"exactness"
];
}
// Define function that do data represent of DataObject for save in Meilisearch
public function getMeilisearchDocumentData() : ?array
{
return [
'id' => $this->getId()
// ... other calculated props
];
// or `return null;` for pass object index process
}