vendor/massive/search-bundle/Search/EventListener/ZendRebuildSubscriber.php line 41

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the MassiveSearchBundle
  4.  *
  5.  * (c) MASSIVE ART WebServices GmbH
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Massive\Bundle\SearchBundle\Search\EventListener;
  11. use Massive\Bundle\SearchBundle\Search\Adapter\ZendLuceneAdapter;
  12. use Massive\Bundle\SearchBundle\Search\Decorator\IndexNameDecoratorInterface;
  13. use Massive\Bundle\SearchBundle\Search\Event\IndexRebuildEvent;
  14. class ZendRebuildSubscriber
  15. {
  16.     /**
  17.      * @var ZendLuceneAdapter
  18.      */
  19.     private $adapter;
  20.     /**
  21.      * @var IndexNameDecoratorInterface
  22.      */
  23.     private $indexNameDecorator;
  24.     public function __construct(ZendLuceneAdapter $adapterIndexNameDecoratorInterface $indexNameDecorator)
  25.     {
  26.         $this->adapter $adapter;
  27.         $this->indexNameDecorator $indexNameDecorator;
  28.     }
  29.     /**
  30.      * Optimize the search indexes after the index rebuild event has been fired.
  31.      * Should have a priority low enough in order for it to be executed after all
  32.      * the actual index builders.
  33.      */
  34.     public function onIndexRebuild(IndexRebuildEvent $event)
  35.     {
  36.         foreach ($this->adapter->listIndexes() as $indexName) {
  37.             if (!$this->indexNameDecorator->isVariant($this->indexNameDecorator->undecorate($indexName), $indexName)) {
  38.                 continue;
  39.             }
  40.             $event->getOutput()->writeln(\sprintf('<info>Optimizing zend lucene index:</info> %s'$indexName));
  41.             $this->adapter->optimize($indexName);
  42.         }
  43.     }
  44. }