private function updateDirectoryMapping($deleteMapping)
 {
     $es = $this->getContainer()->get('es_client');
     // Elastic Search client
     // Do it for the course mapping
     $params = array();
     $params['index'] = $this->getContainer()->getParameter('es_index_name');
     $params['type'] = 'course';
     if ($deleteMapping) {
         $es->indices()->deleteMapping($params);
     }
     // Get the mapping
     $cDoc = new CourseDocumentType(new Course(), $this->getContainer());
     $mapping = array('_source' => array('enabled' => true), 'properties' => $cDoc->getMapping());
     $params['body']['course'] = $mapping;
     $es->indices()->putMapping($params);
     // Credential Mapping
     $params = array();
     $params['index'] = $this->getContainer()->getParameter('es_index_name');
     $params['type'] = 'credential';
     $credentialDoc = new CredentialDocumentType(new \ClassCentral\CredentialBundle\Entity\Credential(), $this->getContainer());
     if ($deleteMapping) {
         $es->indices()->deleteMapping($params);
     }
     $mapping = array('_source' => array('enabled' => true), 'properties' => $credentialDoc->getMapping());
     $params['body']['credential'] = $mapping;
     $es->indices()->putMapping($params);
     // Suggest Document mapping
     $params = array();
     $params['index'] = $this->getContainer()->getParameter('es_index_name');
     $params['type'] = 'suggest';
     if ($deleteMapping) {
         $es->indices()->deleteMapping($params);
     }
     // Get the mapping
     $sDoc = new SuggestDocumentType(new Course(), $this->getContainer());
     $mapping = array('_source' => array('enabled' => true), 'properties' => $sDoc->getMapping());
     $params['body']['suggest'] = $mapping;
     $es->indices()->putMapping($params);
 }
예제 #2
0
 /**
  * Index the particular entity
  * @param $entity
  */
 public function index($entity, $indexName = null)
 {
     $this->esClient = $this->container->get('es_client');
     // Index the course
     if ($entity instanceof Course) {
         $cDoc = new CourseDocumentType($entity, $this->container);
         $doc = $cDoc->getDocument($this->getIndexName('es_index_name'));
         $this->esClient->index($doc);
         // Add the course to the Suggest documents
         if ($entity->getStatus() < 100) {
             $csDoc = new SuggestDocumentType($entity, $this->container);
             $doc = $csDoc->getDocument($this->getIndexName('es_index_name'));
             $this->esClient->index($doc);
         }
     }
     // Index the Credential
     if ($entity instanceof Credential) {
         $cDoc = new CredentialDocumentType($entity, $this->container);
         $doc = $cDoc->getDocument($this->getIndexName('es_index_name'));
         $this->esClient->index($doc);
         if ($entity->getStatus() < 100) {
             $csDoc = new SuggestDocumentType($entity, $this->container);
             $doc = $csDoc->getDocument($this->getIndexName('es_index_name'));
             $this->esClient->index($doc);
         }
     }
     // Index the institution
     if ($entity instanceof Institution) {
         // Add the institution to document suggestions
         $isDoc = new SuggestDocumentType($entity, $this->container);
         $doc = $isDoc->getDocument($this->getIndexName('es_index_name'));
         $this->esClient->index($doc);
     }
     // Index the Language
     if ($entity instanceof Language) {
         // Add Language to document suggestions
         $isDoc = new SuggestDocumentType($entity, $this->container);
         $doc = $isDoc->getDocument($this->getIndexName('es_index_name'));
         $this->esClient->index($doc);
     }
     if ($entity instanceof Stream) {
         $sDoc = new SubjectDocumentType($entity, $this->container);
         $doc = $sDoc->getDocument($this->getIndexName('es_index_name'));
         $this->esClient->index($doc);
         // Add the subject to document suggestions
         $ssDoc = new SuggestDocumentType($entity, $this->container);
         $doc = $ssDoc->getDocument($this->getIndexName('es_index_name'));
         $this->esClient->index($doc);
     }
     if ($entity instanceof Initiative) {
         $ssDoc = new SuggestDocumentType($entity, $this->container);
         $doc = $ssDoc->getDocument($this->getIndexName('es_index_name'));
         $this->esClient->index($doc);
     }
     if ($entity instanceof ESJob) {
         $jobDoc = new ESJobDocumentType($entity, $this->container);
         $doc = $jobDoc->getDocument($this->getIndexName('es_scheduler_index_name'));
         $this->esClient->index($doc);
     }
     if ($entity instanceof ESJobLog) {
         $jobLogDoc = new ESJobLogDocumentType($entity, $this->container);
         $doc = $jobLogDoc->getDocument($this->getIndexName('es_scheduler_index_name'));
         $this->esClient->index($doc);
     }
 }