psvneo / typo3-extension-meilisearch
此扩展将 "meilisearch" 集成到您的 TYPO3 中。
0.5.5
2024-08-20 13:49 UTC
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
此扩展将 meilisearch 集成到您的 TYPO3。
需求
- TYPO3 ^12.4
- PHP ^8.1
安装
使用 composer 将扩展添加到您的项目中。
composer require psvneo/typo3-extension-meilisearch
您还可以从这里下载扩展 here。
设置/配置
将以下内容添加到您要使用 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: https://: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)%'
如何索引
此命令将执行系统找到的所有索引器。
vendor/bin/typo3 meilisearch:index MY_SITE_IDENTIFIER
在索引新运行前清除索引
vendor/bin/typo3 meilisearch:index MY_SITE_IDENTIFIER -f
如何创建自己的索引器
索引器通过 DI 标签收集。为了提高开发体验,我们添加了一个 编译器,因此您无需注册索引器。您只需确保您的索引器可作为 服务 可用。
要创建索引器,您可以
- 实现
\PSVNEO\Meilisearch\Domain\Indexer\IndexerInterface
或 - 从
\PSVNEO\Meilisearch\Domain\Indexer\AbstractIndexer
继承。
使用接口创建自己的索引器
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',
]
}
}
我们建议您从
\PSVNEO\Meilisearch\Domain\Indexer\AbstractIndexer
继承。这将为您提供的索引器提供一些 TYPO3-Record 基础,并为您提供\PSVNEO\Meilisearch\Domain\Indexer\AbstractIndexer::getQueryBuilder
方法,以便快速开始您的数据库查询。
通过扩展 AbstractIndexer 类创建自己的索引器
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.
}
}
...