Beispiel #1
0
 public static function get()
 {
     //Entity loader
     $entities = Config::getEntityNamespacePath();
     //Annotation metadata driver
     $config = new Configuration();
     $md = $config->newDefaultAnnotationDriver(array($entities['path']));
     $config->setMetadataDriverImpl($md);
     $config->setMetadataCacheImpl(new ArrayCache());
     //Set and configure preferred serializer for persistence
     //If using serialaztion groups you can sepcify the names here
     $config->setEntitySerializer(new JMSSerializer(SerializationContext::create()->setGroups('store')));
     //Add event listeners here
     $eventManager = new EventManager();
     //$eventManager->addEventListener('prePersist', $listener);
     //Create the client
     $client = new Client(array('connections' => Config::getServers()));
     //Get the search manager
     return new SearchManager($config, new ElasticaAdapter($client), $eventManager);
 }
 /**
  * (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;
 }
Beispiel #3
0
 /**
  * @expectedException \PHPUnit_Framework_Error
  */
 public function testNewDefaultAnnotationDriverWrongParameter()
 {
     $this->configuration->newDefaultAnnotationDriver(new \StdClass());
 }