Beispiel #1
0
 protected function getMostAccurateType($types, $resource, $output, $class)
 {
     $mostAccurateType = null;
     $mostAccurateTypes = $this->filiationBuilder->getMostAccurateType($types, $this->serializerHelper->getAllTypes());
     // not specified in project ontology description
     if (count($mostAccurateTypes) == 1) {
         $mostAccurateType = $mostAccurateTypes[0];
     } else {
         if ($mostAccurateTypes === null) {
             $output->writeln("No accurate type found for " . $resource->getUri() . ". The type {$class} will be used.");
             $mostAccurateType = $class;
         } else {
             $output->writeln("The most accurate type for " . $resource->getUri() . " has not be found. The resource will not be indexed.");
         }
     }
     return $mostAccurateType;
 }
Beispiel #2
0
 /**
  * Search parent frame pathes
  * @param $parentClass
  * @param array $parentFrames
  * @return array
  */
 public function getParentFrames($type)
 {
     $parentClasses = $this->filiationBuilder->getParentTypes($type);
     $parentFrames = array();
     if (!$parentClasses || empty($parentClasses)) {
         return $parentFrames;
     }
     foreach ($parentClasses as $parentClass) {
         $phpClass = TypeMapper::get($parentClass);
         if ($phpClass) {
             $metadata = $this->metadataFactory->getMetadataForClass($phpClass);
             $frame = $metadata->getFrame();
             if ($frame) {
                 $parentFrames[] = $metadata->getFrame();
             }
         }
     }
     return $parentFrames;
 }
 /**
  * If a types resource has changed and the new type is mapped to another document type, then the old document is removed
  * @param $uri
  * @param $types
  * @param $oldType
  * @return bool
  */
 protected function deleteOldDocument($uri, $types, $oldType)
 {
     $newTypes = array();
     foreach ($types as $type) {
         $type = (string) $type;
         if ($type && !empty($type)) {
             $newTypes[] = RdfNamespace::shorten($type);
         }
     }
     // Get most accurtype of oldtype
     $mostAccurateTypes = $this->filiationBuilder->getMostAccurateType(array(RdfNamespace::expand($oldType)), $this->serializerHelper->getAllTypes());
     $mostAccurateType = null;
     // not specified in project ontology description
     if (count($mostAccurateTypes) == 1) {
         $mostAccurateType = $mostAccurateTypes[0];
     } else {
         //            echo "Seems to not have to be indexed";
     }
     if (!in_array($mostAccurateType, $newTypes)) {
         $typesConfig = $this->configManager->getTypesConfigurationByClass($mostAccurateType);
         foreach ($typesConfig as $typeConfig) {
             $indexConfig = $typeConfig->getIndex();
             $index = $indexConfig->getName();
             $this->container->get('nemrod.elastica.jsonld.frame.loader')->setEsIndex($index);
             if ($index !== null) {
                 $esType = $this->indexRegistry->getIndex($index)->getType($typeConfig->getType());
                 // Trow an exeption if document does not exist
                 try {
                     $esType->deleteDocument(new Document($uri, array(), $mostAccurateType, $indexConfig->getElasticSearchName()));
                     return true;
                 } catch (\Exception $e) {
                 }
             }
         }
     }
     return false;
 }
 /**
  * Update the elasticsearch document
  * @param string                        $uri
  * @param array                         $types
  * @param string                        $index
  * @param FiliationBuilder              $filiationBuilder
  * @param ResourceToDocumentTransformer $resourceToDocumentTransformer
  */
 public function updateDocument($uri, $types, $filiationBuilder, ResourceToDocumentTransformer $resourceToDocumentTransformer)
 {
     // find the finest type of the resource in order to index the resource ony once
     $typeName = $filiationBuilder->getMostAccurateType($types, $this->serializerHelper->getAllTypes());
     // not specified in project ontology description
     if ($typeName === null) {
         throw new \Exception('No type found to update the ES document ' . $uri);
     } else {
         if (count($typeName) == 1) {
             $typeName = $typeName[0];
         } else {
             throw new \Exception("The most accurate type for " . $uri . " has not be found.");
         }
     }
     $typesConfig = $this->configManager->getTypesConfigurationByClass($typeName);
     foreach ($typesConfig as $typeConfig) {
         $indexConfig = $typeConfig->getIndex();
         $index = $indexConfig->getName();
         $esType = $this->indexRegistry->getIndex($index)->getType($typeConfig->getType());
         $document = $resourceToDocumentTransformer->transform($uri, $index, $typeName);
         if ($document) {
             $esType->addDocument($document);
         }
     }
 }