Navigation Menu

Skip to content

1drop/ext-solr-extbase

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

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

Contributions

Feel free to give us a pull request.

Onedrop Solutions GmbH & Co. KG

About

Extbase indexation for TYPO3 Solr

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages