Extbase integration into Apache Solr for TYPO3 CMS
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., (*1)
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., (*2)
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., (*3)
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)., (*4)
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
., (*5)
Documentation and Support
-
Slack Channel:, (*6)
https://typo3.slack.com/messages/ext-solr/, (*7)
(request your invite for Slack here: https://forger.typo3.org/slack), (*8)
Contributions
Feel free to give us a pull request., (*9)
, (*10)