protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     $this->schema->onIndexDropped[] = function ($sm, $index) use($output) {
         $output->writeln(sprintf('<error>Dropped</error> index <info>%s</info>', $index));
     };
     $this->schema->onTypeDropped[] = function ($sm, ClassMetadata $type) use($output) {
         $output->writeln(sprintf('<error>Dropped</error> type <info>%s</info>', $type->getName()));
     };
     $this->schema->onIndexCreated[] = function ($sm, $index) use($output) {
         $output->writeln(sprintf('Created index <info>%s</info>', $index));
     };
     $this->schema->onTypeCreated[] = function ($sm, ClassMetadata $type) use($output) {
         $output->writeln(sprintf('Created type <info>%s</info>', $type->getName()));
     };
     $this->schema->onAliasCreated[] = function ($sm, $original, $alias) use($output) {
         $output->writeln(sprintf('Created alias <info>%s</info> for index <info>%s</info>', $alias, $original));
     };
     $this->schema->onAliasError[] = function ($sm, ResponseException $e, $original, $alias) use($output) {
         $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
     };
     /** @var \Doctrine\Search\ElasticSearch\Client $searchClient */
     $searchClient = $this->searchManager->getClient();
     /** @var Kdyby\ElasticSearch\Client $apiClient */
     $apiClient = $searchClient->getClient();
     $apiClient->onError = [];
     $apiClient->onSuccess = [];
 }
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     /** @var \Doctrine\Search\ElasticSearch\Client $searchClient */
     $searchClient = $this->searchManager->getClient();
     /** @var Kdyby\ElasticSearch\Client $apiClient */
     $apiClient = $searchClient->getClient();
     $apiClient->onError = [];
     $apiClient->onSuccess = [];
 }
 /**
  * Execute a direct delete by query on the associated index and type
  *
  * @param object $query
  */
 public function delete($query)
 {
     $classes = $this->getClassMetadata();
     foreach ($classes as $class) {
         $this->_sm->getClient()->removeAll($class, $query);
     }
 }
Example #4
0
 /**
  * @param BaseElasticsearchEntity $entity
  * @param bool $refresh
  *
  * @throws \Exception
  */
 public function save($entity, $refresh = false)
 {
     $this->_sm->persist($entity);
     $this->_sm->flush($entity);
     if ($refresh) {
         $this->_sm->getClient()->refreshIndex($this->getClassMetadata()->getIndexForWrite($entity->toESDocument()));
     }
 }
 /**
  * (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;
 }
Example #6
0
 /**
  * Load and hydrate a document collection
  *
  * @param array $classes
  * @param unknown $query
  */
 public function loadCollection(array $classes, $query)
 {
     $results = $this->sm->getClient()->search($query, $classes);
     return $this->hydrateCollection($classes, $results);
 }
Example #7
0
 /**
  * Execute a direct delete by query on the associated index and type
  *
  * @param object $query
  */
 public function delete($query)
 {
     $this->_sm->getClient()->removeAll($this->_class, $query);
 }
Example #8
0
 public function __construct(SearchManager $sm, $env)
 {
     $this->sm = $sm;
     $this->client = $sm->getClient();
     $this->env = $env;
 }