onedrop/solr-extbase

Extbase indexing addition to Apache Solr for TYPO3

Installs: 131

Dependents: 0

Suggesters: 0

Security: 0

Stars: 9

Watchers: 6

Forks: 0

Open Issues: 0

Type:typo3-cms-extension

0.0.2 2016-05-29 10:59 UTC

This package is auto-updated.

Last update: 2024-09-25 06:33:52 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

Contributions

Feel free to give us a pull request.

Onedrop Solutions GmbH & Co. KG