diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 49b7b97..ae27860 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -189,6 +189,7 @@ class Configuration implements ConfigurationInterface return $v; }) ->end() + // BC - Support the old is_indexable_callback property ->beforeNormalization() ->ifTrue(function ($v) { return isset($v['persistence']) && @@ -202,6 +203,25 @@ class Configuration implements ConfigurationInterface return $v; }) ->end() + // Support multiple dynamic_template formats to match the old bundle style + // and the way ElasticSearch expects them + ->beforeNormalization() + ->ifTrue(function ($v) { return isset($v['dynamic_templates']); }) + ->then(function ($v) { + $dt = array(); + foreach ($v['dynamic_templates'] as $key => $type) { + if (is_numeric($key)) { + $dt[$key] = $type; + } else { + $dt[][$key] = $type; + } + } + + $v['dynamic_templates'] = $dt; + + return $v; + }) + ->end() ->children() ->scalarNode('index_analyzer')->end() ->scalarNode('search_analyzer')->end() diff --git a/Index/MappingBuilder.php b/Index/MappingBuilder.php index 4a6c70a..f3474be 100644 --- a/Index/MappingBuilder.php +++ b/Index/MappingBuilder.php @@ -60,6 +60,10 @@ class MappingBuilder // 'search_analyzer' => $typeConfig->getSearchAnalyzer(), )); + if (isset($mapping['dynamic_templates']) and empty($mapping['dynamic_templates'])) { + unset($mapping['dynamic_templates']); + } + $this->fixProperties($mapping['properties']); if ($typeConfig->getModel()) { @@ -69,31 +73,6 @@ class MappingBuilder return $mapping; } - /** - * create type mapping object - * - * @param array $indexConfig - * @return Mapping - */ - protected function createMapping($indexConfig) - { - /*$mapping = $this->createMapping($indexConfig['config']['properties'][$typeName]);*/ - $mapping = Mapping::create($indexConfig['properties']); - - $mappingSpecialFields = array('_uid', '_id', '_source', '_all', '_analyzer', '_boost', '_routing', '_index', '_size', '_timestamp', '_ttl', 'dynamic_templates'); - foreach ($mappingSpecialFields as $specialField) { - if (isset($indexConfig[$specialField])) { - $mapping->setParam($specialField, $indexConfig[$specialField]); - } - } - - if (isset($indexConfig['_parent'])) { - $mapping->setParam('_parent', array('type' => $indexConfig['_parent']['type'])); - } - - return $mapping; - } - /** * Fixes any properties and applies basic defaults for any field that does not have * required options. diff --git a/Tests/Functional/app/Basic/config.yml b/Tests/Functional/app/Basic/config.yml index 0f2403b..cdc6c53 100644 --- a/Tests/Functional/app/Basic/config.yml +++ b/Tests/Functional/app/Basic/config.yml @@ -29,11 +29,26 @@ fos_elastica: max_gram: 5 types: parent: + dynamic_templates: + dates: + match: "date_*" + mapping: + type: date mappings: field1: ~ field2: ~ type: search_analyzer: my_analyzer + dynamic_templates: + - dates: + match: "date_*" + mapping: + type: date + - strings: + match: "*" + mapping: + analyzer: english + type: string mappings: field1: ~ field2: