onedrop / solr-extbase
Extbase indexing addition to Apache Solr for TYPO3
Installs: 132
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 6
Forks: 0
Open Issues: 0
Type:typo3-cms-extension
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-10-25 06:39:41 UTC
README
This integration gives you the easy possibility to use your extbase entities during solr indexation. Very often you want to access related records and don't want to clone your business logic into TypoScript to select related records.
What does it do?
- Hooks into extbase repositories added/modified/deleted methods to update the record in solr`s indexQueue
- Provides a way to switch the language when loading extbase records (needed for correct indexation)
- Provides an interface that must be inherited by extbase models to be indexable
Usage
Assumption: You already have an indexQueue configured in solr as usual and mapped fields from TCA to the solr document.
Add IndexableEntity
interface to the desired entity model
<?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; }
The method addEntityFieldsToDocument
is processed after the document has been generated by the usual
solr indexer using the TypoScript configuration. Therefore you can add new fields or overwrite fields using the setField
method.
As you might have some constraints in your business logic that makes the models visible for search, you can modify the
method isIndexable
to match your custom constraints. If the method evaluates to false
the model will not be indexed
(not even the basic fields configured in TypoScript).
Modify solr configuration to use the extbase indexer
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
}
}
}
You must set the indexer of the indexQueue and the repository that will be used to load the model using findByUid
.
Documentation and Support
-
Slack Channel:
https://typo3.slack.com/messages/ext-solr/
(request your invite for Slack here: https://forger.typo3.org/slack)
Contributions
Feel free to give us a pull request.