Merge branch 'detection-config'

This commit is contained in:
Tim Nagel 2015-01-04 22:12:21 +11:00
commit c39b86c6c5
9 changed files with 58 additions and 10 deletions

View file

@ -14,6 +14,8 @@ https://github.com/FriendsOfSymfony/FOSElasticaBundle/compare/v3.0.4...v3.1.0
* BC BREAK: `Doctrine\Listener#scheduleForDeletion` access changed to private.
* BC BREAK: `ObjectPersisterInterface` gains the method `handlesObject` that
returns a boolean value if it will handle a given object or not.
* Removed `Doctrine\Listener#getSubscribedEvents`. The container
* BC BREAK: Removed `Doctrine\Listener#getSubscribedEvents`. The container
configuration now configures tags with the methods to call to avoid loading
this class on every request where doctrine is active.
this class on every request where doctrine is active. #729
* Added ability to configure `date_detection`, `numeric_detection` and
`dynamic_date_formats` for types. #753

View file

@ -35,6 +35,22 @@ class TypeConfig
$this->name = $name;
}
/**
* @return bool|null
*/
public function getDateDetection()
{
return $this->getConfig('date_detection');
}
/**
* @return array
*/
public function getDynamicDateFormats()
{
return $this->getConfig('dynamic_date_formats');
}
/**
* @return string|null
*/
@ -61,6 +77,14 @@ class TypeConfig
null;
}
/**
* @return bool|null
*/
public function getNumericDetection()
{
return $this->getConfig('numeric_detection');
}
/**
* @return string
*/

View file

@ -235,7 +235,10 @@ class Configuration implements ConfigurationInterface
})
->end()
->children()
->booleanNode('date_detection')->end()
->arrayNode('dynamic_date_formats')->prototype('scalar')->end()->end()
->scalarNode('index_analyzer')->end()
->booleanNode('numeric_detection')->end()
->scalarNode('search_analyzer')->end()
->variableNode('indexable_callback')->end()
->append($this->getPersistenceNode())

View file

@ -241,6 +241,9 @@ class FOSElasticaExtension extends Extension
'serializer',
'index_analyzer',
'search_analyzer',
'date_detection',
'dynamic_date_formats',
'numeric_detection',
) as $field) {
$typeConfig['config'][$field] = array_key_exists($field, $type) ?
$type[$field] :

View file

@ -58,13 +58,19 @@ class MappingBuilder
*/
public function buildTypeMapping(TypeConfig $typeConfig)
{
$mapping = array_merge($typeConfig->getMapping(), array(
// 'date_detection' => true,
// 'dynamic_date_formats' => array()
// 'dynamic_templates' => $typeConfig->getDynamicTemplates(),
// 'numeric_detection' => false,
// 'properties' => array(),
));
$mapping = $typeConfig->getMapping();
if (null !== $typeConfig->getDynamicDateFormats()) {
$mapping['dynamic_date_formats'] = $typeConfig->getDynamicDateFormats();
}
if (null !== $typeConfig->getDateDetection()) {
$mapping['date_detection'] = $typeConfig->getDateDetection();
}
if (null !== $typeConfig->getNumericDetection()) {
$mapping['numeric_detection'] = $typeConfig->getNumericDetection();
}
if ($typeConfig->getIndexAnalyzer()) {
$mapping['index_analyzer'] = $typeConfig->getIndexAnalyzer();

View file

@ -42,6 +42,9 @@ class Resetter
/**
* Deletes and recreates all indexes
*
* @param bool $populating
* @param bool $force
*/
public function resetAllIndexes($populating = false, $force = false)
{

View file

@ -49,6 +49,9 @@ class MappingToElasticaTest extends WebTestCase
$mapping = $type->getMapping();
$this->assertNotEmpty($mapping, 'Mapping was populated');
$this->assertFalse($mapping['type']['date_detection']);
$this->assertTrue($mapping['type']['numeric_detection']);
$this->assertEquals(array('yyyy-MM-dd'), $mapping['type']['dynamic_date_formats']);
$this->assertArrayHasKey('store', $mapping['type']['properties']['field1']);
$this->assertTrue($mapping['type']['properties']['field1']['store']);
$this->assertArrayNotHasKey('store', $mapping['type']['properties']['field2']);
@ -105,6 +108,7 @@ class MappingToElasticaTest extends WebTestCase
/**
* @param Client $client
* @param string $type
* @return \Elastica\Type
*/
private function getType(Client $client, $type = 'type')

View file

@ -46,6 +46,8 @@ fos_elastica:
index_analyzer: my_analyzer
type:
search_analyzer: my_analyzer
date_detection: false
dynamic_date_formats: [ 'yyyy-MM-dd' ]
dynamic_templates:
- dates:
match: "date_*"
@ -56,6 +58,7 @@ fos_elastica:
mapping:
analyzer: english
type: string
numeric_detection: true
properties:
field1: ~
field2:

View file

@ -28,7 +28,7 @@ fos_elastica:
serializer: ~
indexes:
index:
index_name: foselastica_test_%kernel.environment%
index_name: foselastica_ser_test_%kernel.environment%
types:
type:
properties: