Add tests and normalisation to support old dynamic_templates format
This commit is contained in:
parent
c9a24436f3
commit
5d65676659
|
@ -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()
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue