psvneo / typo3-extension-meilisearch
This extension integrates "meilisearch" into your TYPO3.
Requires
- php: ^8.1
- meilisearch/meilisearch-php: ^1.4
- symfony/console: ^5.4 || ^6.4 || ^7.0
- typo3/cms-backend: ^12.4
- typo3/cms-core: ^12.4
- typo3/cms-extbase: ^12.4
- typo3/cms-fluid: ^12.4
- typo3/cms-frontend: ^12.4
Requires (Dev)
- psvneo/qa-toolset-t3: ^2.0
Replaces
- typo3-ter/meilisearch: 0.5.5
README
This extension integrates meilisearch into your TYPO3.
Requirements
- TYPO3 ^12.4
- PHP ^8.1
Installation
Use composer to add the extension to your project.
composer require psvneo/typo3-extension-meilisearch
You can also download the extension from the TER here.
Setup / Configuration
Add the following to the site configuration where you want to use meilisearch.
meilisearch:
# The main/first index to search in.
mainIndex: 'typo3_pages'
# Search result - Attributes to highlight.
attributesToHighlight: ['*']
# Search result - Attributes to crop.
attributesToCrop: ['title:1', 'searchContent:5']
# URL to your meilisearch service.
serviceUrl: http://localhost:7700
# Search API Key. Please use a readonly key here!
searchApiKey: '%env(MEILISEARCH_SEARCH_APIKEY)%'
# Admin API Key. This key is used to index yur data.
adminApiKey: '%env(MEILISEARCH_ADMIN_APIKEY)%'
How to index
This command will execute every indexer found by the system.
vendor/bin/typo3 meilisearch:index MY_SITE_IDENTIFIER
To also flush the index before indexing new run:
vendor/bin/typo3 meilisearch:index MY_SITE_IDENTIFIER -f
How to create your own indexer
Indexer are getting collected via DI tags. To increase the developer experience we have added a CompilerPass, so you do not have to register your indexer at all. You only have to make sure that your indexer is available as a service.
To create an indexer you can:
- implement
\PSVNEO\Meilisearch\Domain\Indexer\IndexerInterface
or - extend from
\PSVNEO\Meilisearch\Domain\Indexer\AbstractIndexer
.
Create your own indexer using the interface
declare(strict_types=1);
namespace Vendor\ExtensionName\Domain\Indexer;
use TYPO3\CMS\Core\Site\Entity\Site;
final class MyAwesomeIndexer implements IndexerInterface
{
public function collectDocuments(Site $site): array
{
return [] // TODO Add logic to get my documents to index.
}
public function getIndexName(): string
{
return 'my_awesome_index'; // The name of the index in meilisearch.
}
public function getPrimaryKeyName(): string
{
return 'uid' // Or your custom identifier.
}
/**
* @return array<non-empty-string>
*/
public function getFilterableAttributes(): array
{
// Add all filterable fields of your documents here.
return [
'sysLanguageUid',
'rootPageUid',
]
}
}
We recommend you to extend from
\PSVNEO\Meilisearch\Domain\Indexer\AbstractIndexer
. This will provide your indexer with some TYPO3-Record basics and also gives you the method\PSVNEO\Meilisearch\Domain\Indexer\AbstractIndexer::getQueryBuilder
to quickly start with your own database queries.
Create your own indexer extending the AbstractIndexer class
declare(strict_types=1);
namespace Vendor\ExtensionName\Domain\Indexer;
use TYPO3\CMS\Core\Site\Entity\Site;
final class MyAwesomeIndexer extends AbstractIndexer
{
public function collectDocuments(Site $site): array
{
return $this->getQueryBuilder()
->select('*')
->from('my_awesome_table')
->executeQuery()
->fetchAllAssociative();
}
public function getIndexName(): string
{
return 'my_awesome_index'; // The name of the index in meilisearch.
}
}
...