示例#1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $printMapping = $output->getVerbosity() > $output::VERBOSITY_NORMAL;
     $metadataFactory = $this->searchManager->getMetadataFactory();
     /** @var ClassMetadata $class */
     foreach ($metadataFactory->getAllMetadata() as $class) {
         $output->writeln(sprintf('Entity <info>%s</info> is searchable', $class->getName()));
         if (!$printMapping) {
             continue;
         }
         $meta = (array) $class;
         unset($meta['reflFields'], $meta['reflClass']);
         $output->writeln(Dumper::toTerminal($meta));
     }
 }
示例#2
0
 public function indexEntities(ClassMetadata $searchMeta)
 {
     foreach ($this->searchManager->getMetadataFactory()->getAllMetadata() as $otherMeta) {
         if ($searchMeta->className === $otherMeta->className) {
             continue;
         }
         if (is_subclass_of($searchMeta->className, $otherMeta->className)) {
             $this->onChildSkipped($this, $searchMeta, $otherMeta);
             return;
         }
     }
     if ($searchMeta->riverImplementation) {
         $river = $this->serviceLocator->getByType($searchMeta->riverImplementation);
     } else {
         /** @var River\DefaultEntityRiver $river */
         $river = $this->serviceLocator->createInstance('Kdyby\\DoctrineSearch\\River\\DefaultEntityRiver');
     }
     if (!$river instanceof EntityRiver) {
         throw new UnexpectedValueException('The river must implement Doctrine\\Search\\EntityRiver.');
     }
     if (property_exists($river, 'onIndexStart')) {
         $river->onIndexStart[] = function (EntityRiver $river, $paginator, ORMMetadata $class) {
             $this->onIndexStart($this, $paginator, $river, $class);
         };
     }
     if (property_exists($river, 'onItemsIndexed')) {
         $river->onItemsIndexed[] = function ($self, $entities) {
             $this->onItemsIndexed($this, $entities);
         };
     }
     if (property_exists($river, 'onIndexStats')) {
         $river->onIndexStats[] = function ($self, ORMMetadata $class, $timeToIndex, $timeToRead) {
             $this->onIndexStats($this, $class, $timeToIndex, $timeToRead);
         };
     }
     // disable logger
     $config = $this->entityManager->getConfiguration();
     $oldLogger = $config->getSQLLogger();
     $config->setSQLLogger(NULL);
     $river->transfuse($searchMeta);
     $config->setSQLLogger($oldLogger);
 }
示例#3
0
 /**
  * Delete all indices
  */
 public function deleteAllIndices()
 {
     /** @var ClassMetadata[] $metadatas */
     $metadatas = $this->sm->getMetadataFactory()->getAllMetadata();
     foreach ($metadatas as $metadata) {
         try {
             $this->client->deleteIndex($metadata->getIndexForRead());
         } catch (ResponseException $e) {
             if (strpos($e->getResponse()->getError(), 'IndexMissingException') === false) {
                 // The original error from ES is not "IndexMissingException". We shouldn't swallow it.
                 throw $e;
             }
             // The index has been deleted already, skip it.
         }
     }
 }
 /**
  * (non-PHPdoc)
  *
  * @see \Zend\ServiceManager\FactoryInterface::createService()
  *
  * @return \Doctrine\Search\SearchManager
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $this->setServiceLocator($serviceLocator);
     $config = $serviceLocator->get('Config');
     $clientConfig = isset($config['elastica']['clients']) ? $config['elastica']['clients'] : [];
     $entityConfig = isset($config['elastica']['entities']) ? $config['elastica']['entities'] : ['paths' => []];
     $indicesConfig = isset($config['elastica']['indices']) ? $config['elastica']['indices'] : [];
     $serializationGroups = isset($config['elastica']['serialization']['groups']) ? $config['elastica']['serialization']['groups'] : [];
     $searchConfig = new Configuration();
     $md = $searchConfig->newDefaultAnnotationDriver($entityConfig['paths']);
     $searchConfig->setMetadataDriverImpl($md);
     $searchConfig->setMetadataCacheImpl(new ArrayCache());
     $serializationContext = SerializationContext::create();
     $serializationContext->enableMaxDepthChecks()->setGroups($serializationGroups);
     $searchConfig->setEntitySerializer(new JMSSerializer($serializationContext));
     $eventManager = new EventManager();
     $searchManager = new SearchManager($searchConfig, new ElasticSearchClient(new ElasticaClient(['connections' => $clientConfig])), $eventManager);
     try {
         $client = $searchManager->getClient();
         $metadatas = $searchManager->getMetadataFactory()->getAllMetadata();
         // Create indexes and types
         foreach ($metadatas as $metadata) {
             $config = isset($indicesConfig[$metadata->index]['settings']) ? $indicesConfig[$metadata->index]['settings'] : [];
             if (!$client->getIndex($metadata->index)->exists()) {
                 $client->createIndex($metadata->index, $config);
             }
             $client->createType($metadata);
         }
     } catch (\Exception $e) {
         $this->getFlashMessenger()->addErrorMessage($e->getMessage());
         /* @var $logger \Zend\Log\Logger */
         $logger = $serviceLocator->get('logger');
         $logger->debug($e->getMessage());
     }
     return $searchManager;
 }