/** * 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); } } }
/** * @throws \Exception */ protected function cascadeRemoveDocuments() { // cascade remove foreach ($this->arrayResourcesToUpdateAfterDeletion as $uri => $type) { $typesConfig = $this->configManager->getTypesConfigurationByClass($type); foreach ($typesConfig as $typeConfig) { $indexConfig = $typeConfig->getIndex(); $index = $indexConfig->getName(); $this->container->get('nemrod.elastica.jsonld.frame.loader')->setEsIndex($index); if ($index !== null) { $this->cascadeUpdateHelper->updateDocument($uri, array($type), $this->filiationBuilder, $this->resourceToDocumentTransformer); } } } }