Beispiel #1
0
 /**
  * @param $index
  * @param null $output
  */
 public function resetIndex($index, $output = null)
 {
     $indexObj = $this->indexRegistry->getIndex($index);
     $config = $this->configManager->getIndexConfiguration($index)->getSettings();
     if (!$indexObj->exists()) {
         $indexObj->create($config);
     } else {
         $indexObj->close();
         $indexObj->setSettings($config);
         $indexObj->open();
     }
 }
Beispiel #2
0
 /**
  * @param $index
  * @param $type
  * @return array
  * @throws \Exception
  */
 protected function getTypesToPopulate($index, $type = null)
 {
     $indexObj = $this->indexRegistry->getIndex($index);
     if (!$indexObj) {
         throw new \Exception("The index {$index} is not defined");
     }
     // creating index if not exists
     if (!$indexObj->exists()) {
         $this->resetter->resetIndex($index);
     }
     $typesConfig = $this->configManager->getIndexConfiguration($index)->getTypes();
     if ($type) {
         if (!isset($typesConfig[$type])) {
             throw new \Exception("The type {$type} is not defined in this index.");
         }
         $typeConfig = $typesConfig[$type];
         $types = array($type => $indexObj->getType($typeConfig->getType()));
     } else {
         $this->resetter->reset($index);
         $types = array_combine(array_keys($typesConfig), array_map(function (TypeConfig $typeConfig) use($indexObj) {
             return $indexObj->getType($typeConfig->getType());
         }, $typesConfig));
     }
     return $types;
 }
 /**
  * Transform a resource to an elastica document.
  *
  * @param $uri
  * @param $index
  * @param $type
  *
  * @return Document|null
  */
 public function transform($uri, $index, $type)
 {
     if ($index && $this->serializerHelper->isTypeIndexed($index, $type)) {
         $frame = $this->serializerHelper->getTypeFramePath($index, $type);
         $phpClass = TypeMapper::get($type);
         if (!$phpClass) {
             $phpClass = "EasyRdf\\Resource";
         }
         $jsonLd = $this->jsonLdSerializer->serialize(new $phpClass($uri), $frame, array("includeParentClassFrame" => true));
         $graph = json_decode($jsonLd, true);
         if (!isset($graph['@graph'][0])) {
             return;
         }
         $resource = $graph['@graph'][0];
         $resource['@id'] = $uri;
         $json = json_encode($resource);
         $json = str_replace('@id', '_id', $json);
         $json = str_replace('@type', '_type', $json);
         $index = $this->configManager->getIndexConfiguration($index)->getElasticSearchName();
         return new Document($uri, $json, $type, $index);
     }
     return;
 }