onedrop / solr-extbase
Apache Solr 为 TYPO3 的 Extbase 索引扩展
0.0.2
2016-05-29 10:59 UTC
Requires
- php: >=5.5.0
- apache-solr-for-typo3/solr: *
- typo3/cms-core: >=7.6.0
Requires (Dev)
- phpunit/phpunit: >=4.8.0 <6.0.0
This package is auto-updated.
Last update: 2024-09-25 06:33:52 UTC
README
此集成提供了在 Solr 索引期间使用您的 Extbase 实体的简便方式。您通常希望访问相关记录,而不希望将业务逻辑克隆到 TypoScript 中以选择相关记录。
它做什么?
- 钩子到 extbase 存储库中添加/修改/删除方法,以更新 solr 的 indexQueue 中的记录
- 提供了一种在加载 extbase 记录时切换语言的方法(对于正确索引是必需的)
- 提供了一个接口,extbase 模型必须继承此接口才能进行索引
用法
假设:您已经像往常一样在 Solr 中配置了索引队列,并将 TCA 字段映射到 solr 文档。
将 IndexableEntity
接口添加到所需的实体模型
<?php namespace Vendor\Extension\Domain\Model; class Foobar extends AbstractEntity implements \Onedrop\SolrExtbase\Domain\Model\IndexableEntity { /** * relatedEntities * * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Vendor\Extension\Domain\Model\RelatedEntity> */ protected $relatedEntities = NULL; public function __construct() { $this->relatedEntities = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); } public function isIndexable() { // Just returning true will cause the model to be indexed according to its enableFields // and all other indexQueue constraints (additionalWhere etc.) return true; } public function addEntityFieldsToDocument(\Apache_Solr_Document $document) { foreach ($this->relatedEntites as $relatedEntity) { $document->addField('relatedUid_intM', $relatedEntity->getUid()); } return $document; }
addEntityFieldsToDocument
方法在通常使用 TypoScript 配置生成的文档之后处理。因此,您可以使用 setField
方法添加新字段或覆盖字段。
由于您的业务逻辑可能有一些限制,使得模型对搜索可见,您可以修改 isIndexable
方法以匹配您的自定义约束。如果该方法评估为 false
,则模型将不会索引(甚至不会索引在 TypoScript 中配置的基本字段)。
修改 solr 配置以使用 extbase 索引器
plugin.tx_solr.index.queue {
myIndexQueue = 1
myIndexQueue {
table = tx_news_domain_model_news
indexer = Onedrop\SolrExtbase\IndexQueue\EntityIndexer
repository = Vendor\Extension\Domain\Repository\FoobarRepository
fields {
title = title
# ... more fields
}
}
}
您必须设置索引队列的索引器和用于使用 findByUid
加载模型的存储库。
文档和支持
-
Slack 频道
https://typo3.slack.com/messages/ext-solr/
(在此处请求 Slack 邀请:https://forger.typo3.org/slack)
贡献
请随意给我们发送拉取请求。