Fix empty mappings for old ES versions
This commit is contained in:
parent
84cf6c79c2
commit
20033709cf
|
@ -7,7 +7,7 @@ php:
|
|||
- 5.6
|
||||
|
||||
before_script:
|
||||
- /usr/share/elasticsearch -v
|
||||
- /usr/share/elasticsearch/bin/elasticsearch -v
|
||||
- sudo /usr/share/elasticsearch/bin/plugin -install elasticsearch/elasticsearch-mapper-attachments/2.0.0
|
||||
- sudo service elasticsearch restart
|
||||
- echo "extension = mongo.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
|
||||
|
|
|
@ -35,6 +35,14 @@ class TypeConfig
|
|||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getIndexAnalyzer()
|
||||
{
|
||||
return $this->getConfig('index_analyzer');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
@ -43,6 +51,9 @@ class TypeConfig
|
|||
return $this->mapping;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getModel()
|
||||
{
|
||||
return isset($this->config['persistence']['model']) ?
|
||||
|
@ -57,4 +68,19 @@ class TypeConfig
|
|||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getSearchAnalyzer()
|
||||
{
|
||||
return $this->getConfig('search_analyzer');
|
||||
}
|
||||
|
||||
private function getConfig($key)
|
||||
{
|
||||
return isset($this->config[$key]) ?
|
||||
$this->config[$key] :
|
||||
null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -220,9 +220,7 @@ class FOSElasticaExtension extends Extension
|
|||
|
||||
foreach (array(
|
||||
'dynamic_templates',
|
||||
'index_analyzer',
|
||||
'properties',
|
||||
'search_analyzer',
|
||||
'_all',
|
||||
'_boost',
|
||||
'_id',
|
||||
|
@ -239,7 +237,9 @@ class FOSElasticaExtension extends Extension
|
|||
|
||||
foreach (array(
|
||||
'persistence',
|
||||
'serializer'
|
||||
'serializer',
|
||||
'index_analyzer',
|
||||
'search_analyzer',
|
||||
) as $field) {
|
||||
$typeConfig['config'][$field] = array_key_exists($field, $type) ?
|
||||
$type[$field] :
|
||||
|
|
|
@ -18,7 +18,7 @@ class MappingBuilder
|
|||
{
|
||||
/**
|
||||
* Skip adding default information to certain fields.
|
||||
*
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $skipTypes = array('completion');
|
||||
|
@ -36,10 +36,11 @@ class MappingBuilder
|
|||
$typeMappings[$typeConfig->getName()] = $this->buildTypeMapping($typeConfig);
|
||||
}
|
||||
|
||||
$mapping = array(
|
||||
'mappings' => $typeMappings,
|
||||
// 'warmers' => $indexConfig->getWarmers(),
|
||||
);
|
||||
$mapping = array();
|
||||
if ($typeMappings) {
|
||||
$mapping['mappings'] = $typeMappings;
|
||||
}
|
||||
// 'warmers' => $indexConfig->getWarmers(),
|
||||
|
||||
$settings = $indexConfig->getSettings();
|
||||
if ($settings) {
|
||||
|
@ -61,22 +62,36 @@ class MappingBuilder
|
|||
// 'date_detection' => true,
|
||||
// 'dynamic_date_formats' => array()
|
||||
// 'dynamic_templates' => $typeConfig->getDynamicTemplates(),
|
||||
// 'index_analyzer' => $typeConfig->getIndexAnalyzer(),
|
||||
// 'numeric_detection' => false,
|
||||
// 'properties' => array(),
|
||||
// 'search_analyzer' => $typeConfig->getSearchAnalyzer(),
|
||||
));
|
||||
|
||||
if ($typeConfig->getIndexAnalyzer()) {
|
||||
$mapping['index_analyzer'] = $typeConfig->getIndexAnalyzer();
|
||||
}
|
||||
|
||||
if ($typeConfig->getSearchAnalyzer()) {
|
||||
$mapping['search_analyzer'] = $typeConfig->getSearchAnalyzer();
|
||||
}
|
||||
|
||||
if (isset($mapping['dynamic_templates']) and empty($mapping['dynamic_templates'])) {
|
||||
unset($mapping['dynamic_templates']);
|
||||
}
|
||||
|
||||
$this->fixProperties($mapping['properties']);
|
||||
if (!$mapping['properties']) {
|
||||
unset($mapping['properties']);
|
||||
}
|
||||
|
||||
if ($typeConfig->getModel()) {
|
||||
$mapping['_meta']['model'] = $typeConfig->getModel();
|
||||
}
|
||||
|
||||
if (!$mapping) {
|
||||
// Empty mapping, we want it encoded as a {} instead of a []
|
||||
$mapping = new \stdClass;
|
||||
}
|
||||
|
||||
return $mapping;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,12 @@ class MappingToElasticaTest extends WebTestCase
|
|||
$this->assertArrayHasKey('store', $mapping['type']['properties']['field1']);
|
||||
$this->assertTrue($mapping['type']['properties']['field1']['store']);
|
||||
$this->assertArrayNotHasKey('store', $mapping['type']['properties']['field2']);
|
||||
|
||||
$parent = $this->getType($client, 'parent');
|
||||
$mapping = $parent->getMapping();
|
||||
|
||||
$this->assertEquals('my_analyzer', $mapping['parent']['index_analyzer']);
|
||||
$this->assertEquals('whitespace', $mapping['parent']['search_analyzer']);
|
||||
}
|
||||
|
||||
public function testResetType()
|
||||
|
@ -101,9 +107,9 @@ class MappingToElasticaTest extends WebTestCase
|
|||
* @param Client $client
|
||||
* @return \Elastica\Type
|
||||
*/
|
||||
private function getType(Client $client)
|
||||
private function getType(Client $client, $type = 'type')
|
||||
{
|
||||
return $client->getContainer()->get('fos_elastica.index.index.type');
|
||||
return $client->getContainer()->get('fos_elastica.index.index.' . $type);
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
|
|
|
@ -42,6 +42,8 @@ fos_elastica:
|
|||
mappings:
|
||||
field1: ~
|
||||
field2: ~
|
||||
search_analyzer: whitespace
|
||||
index_analyzer: my_analyzer
|
||||
type:
|
||||
search_analyzer: my_analyzer
|
||||
dynamic_templates:
|
||||
|
|
Loading…
Reference in a new issue