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;
|
return $v;
|
||||||
})
|
})
|
||||||
->end()
|
->end()
|
||||||
|
// BC - Support the old is_indexable_callback property
|
||||||
->beforeNormalization()
|
->beforeNormalization()
|
||||||
->ifTrue(function ($v) {
|
->ifTrue(function ($v) {
|
||||||
return isset($v['persistence']) &&
|
return isset($v['persistence']) &&
|
||||||
|
@ -202,6 +203,25 @@ class Configuration implements ConfigurationInterface
|
||||||
return $v;
|
return $v;
|
||||||
})
|
})
|
||||||
->end()
|
->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()
|
->children()
|
||||||
->scalarNode('index_analyzer')->end()
|
->scalarNode('index_analyzer')->end()
|
||||||
->scalarNode('search_analyzer')->end()
|
->scalarNode('search_analyzer')->end()
|
||||||
|
|
|
@ -60,6 +60,10 @@ class MappingBuilder
|
||||||
// 'search_analyzer' => $typeConfig->getSearchAnalyzer(),
|
// 'search_analyzer' => $typeConfig->getSearchAnalyzer(),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
if (isset($mapping['dynamic_templates']) and empty($mapping['dynamic_templates'])) {
|
||||||
|
unset($mapping['dynamic_templates']);
|
||||||
|
}
|
||||||
|
|
||||||
$this->fixProperties($mapping['properties']);
|
$this->fixProperties($mapping['properties']);
|
||||||
|
|
||||||
if ($typeConfig->getModel()) {
|
if ($typeConfig->getModel()) {
|
||||||
|
@ -69,31 +73,6 @@ class MappingBuilder
|
||||||
return $mapping;
|
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
|
* Fixes any properties and applies basic defaults for any field that does not have
|
||||||
* required options.
|
* required options.
|
||||||
|
|
|
@ -29,11 +29,26 @@ fos_elastica:
|
||||||
max_gram: 5
|
max_gram: 5
|
||||||
types:
|
types:
|
||||||
parent:
|
parent:
|
||||||
|
dynamic_templates:
|
||||||
|
dates:
|
||||||
|
match: "date_*"
|
||||||
|
mapping:
|
||||||
|
type: date
|
||||||
mappings:
|
mappings:
|
||||||
field1: ~
|
field1: ~
|
||||||
field2: ~
|
field2: ~
|
||||||
type:
|
type:
|
||||||
search_analyzer: my_analyzer
|
search_analyzer: my_analyzer
|
||||||
|
dynamic_templates:
|
||||||
|
- dates:
|
||||||
|
match: "date_*"
|
||||||
|
mapping:
|
||||||
|
type: date
|
||||||
|
- strings:
|
||||||
|
match: "*"
|
||||||
|
mapping:
|
||||||
|
analyzer: english
|
||||||
|
type: string
|
||||||
mappings:
|
mappings:
|
||||||
field1: ~
|
field1: ~
|
||||||
field2:
|
field2:
|
||||||
|
|
Loading…
Reference in a new issue