/** * Builds a Mapping collection from the annotation sources that are present * * @throws \Flowpack\ElasticSearch\Exception * @return \Flowpack\ElasticSearch\Mapping\MappingCollection<\Flowpack\ElasticSearch\Domain\Model\Mapping> */ public function buildMappingInformation() { if (!$this->client instanceof Model\Client) { throw new \Flowpack\ElasticSearch\Exception('No client was given for mapping retrieval. Set a client BackendMappingBuilder->setClient().', 1339678111); } $this->indicesWithoutTypeInformation = array(); $response = $this->client->request('GET', '/_mapping'); $mappingInformation = new MappingCollection(MappingCollection::TYPE_BACKEND); $mappingInformation->setClient($this->client); $indexNames = $this->indexInformer->getAllIndexNames(); foreach ($response->getTreatedContent() as $indexName => $indexSettings) { if (!in_array($indexName, $indexNames)) { continue; } $index = new Model\Index($indexName); if (empty($indexSettings)) { $this->indicesWithoutTypeInformation[] = $indexName; } foreach ($indexSettings as $typeName => $typeSettings) { $type = new Model\GenericType($index, $typeName); $mapping = new Model\Mapping($type); if (isset($typeSettings['properties'])) { foreach ($typeSettings['properties'] as $propertyName => $propertySettings) { foreach ($propertySettings as $key => $value) { $mapping->setPropertyByPath(array($propertyName, $key), $value); } } } $mappingInformation->add($mapping); } } return $mappingInformation; }
/** * Builds a Mapping collection from the annotation sources that are present * * @return \Flowpack\ElasticSearch\Mapping\MappingCollection<\Flowpack\ElasticSearch\Domain\Mapping> */ public function buildMappingInformation() { $mappings = new MappingCollection(MappingCollection::TYPE_ENTITY); foreach ($this->indexInformer->getClassesAndAnnotations() as $className => $annotation) { $mappings->add($this->buildMappingFromClassAndAnnotation($className, $annotation)); } return $mappings; }
/** * Builds a Mapping Collection from the configured node types * * @param \Flowpack\ElasticSearch\Domain\Model\Index $index * @return \Flowpack\ElasticSearch\Mapping\MappingCollection<\Flowpack\ElasticSearch\Domain\Model\Mapping> */ public function buildMappingInformation(Index $index) { $this->lastMappingErrors = new \TYPO3\Flow\Error\Result(); $mappings = new MappingCollection(MappingCollection::TYPE_ENTITY); /** @var NodeType $nodeType */ foreach ($this->nodeTypeManager->getNodeTypes() as $nodeTypeName => $nodeType) { if ($nodeTypeName === 'unstructured' || $nodeType->isAbstract()) { continue; } $type = $index->findType(self::convertNodeTypeNameToMappingName($nodeTypeName)); $mapping = new Mapping($type); // http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-root-object-type.html#_dynamic_templates // 'not_analyzed' is necessary $mapping->addDynamicTemplate('dimensions', array('path_match' => '__dimensionCombinations.*', 'match_mapping_type' => 'string', 'mapping' => array('type' => 'string', 'index' => 'not_analyzed'))); foreach ($nodeType->getProperties() as $propertyName => $propertyConfiguration) { if (isset($propertyConfiguration['search']) && isset($propertyConfiguration['search']['elasticSearchMapping'])) { if (is_array($propertyConfiguration['search']['elasticSearchMapping'])) { $mapping->setPropertyByPath($propertyName, $propertyConfiguration['search']['elasticSearchMapping']); } } elseif (isset($propertyConfiguration['type']) && isset($this->defaultConfigurationPerType[$propertyConfiguration['type']]['elasticSearchMapping'])) { if (is_array($this->defaultConfigurationPerType[$propertyConfiguration['type']]['elasticSearchMapping'])) { $mapping->setPropertyByPath($propertyName, $this->defaultConfigurationPerType[$propertyConfiguration['type']]['elasticSearchMapping']); } } else { $this->lastMappingErrors->addWarning(new \TYPO3\Flow\Error\Warning('Node Type "' . $nodeTypeName . '" - property "' . $propertyName . '": No ElasticSearch Mapping found.')); } } $mappings->add($mapping); } return $mappings; }
/** * Returns a new collection of mappings of this collection that are not member of the $complementCollection. * * @param MappingCollection $complementCollection * @return \Flowpack\ElasticSearch\Mapping\MappingCollection */ public function diffAgainstCollection(MappingCollection $complementCollection) { $returnMappings = new \Flowpack\ElasticSearch\Mapping\MappingCollection(); foreach ($this as $entityMapping) { /** @var $entityMapping \Flowpack\ElasticSearch\Domain\Model\Mapping */ $mapping = new \Flowpack\ElasticSearch\Domain\Model\Mapping(clone $entityMapping->getType()); $saveMapping = FALSE; foreach ($entityMapping->getProperties() as $propertyName => $propertySettings) { foreach ($propertySettings as $entitySettingKey => $entitySettingValue) { $backendSettingValue = $complementCollection->getMappingSetting($entityMapping, $propertyName, $entitySettingKey); if ($entitySettingValue !== $backendSettingValue) { $mapping->setPropertyByPath(array($propertyName, $entitySettingKey), $entitySettingValue); $saveMapping = TRUE; } } } if ($saveMapping) { $returnMappings->add($mapping); } } return $returnMappings; }