1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\NodeSearchBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
6
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
7
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
8
|
|
|
use Kunstmaan\NodeSearchBundle\Helper\ElasticSearchUtil; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* This is the class that validates and merges configuration from your app/config files |
12
|
|
|
* |
13
|
|
|
* To learn more see {@link |
14
|
|
|
* http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class} |
15
|
|
|
*/ |
16
|
|
|
class Configuration implements ConfigurationInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* {@inheritDoc} |
20
|
|
|
*/ |
21
|
|
|
public function getConfigTreeBuilder() |
22
|
|
|
{ |
23
|
|
|
$treeBuilder = new TreeBuilder(); |
24
|
|
|
$rootNode = $treeBuilder->root('kunstmaan_node_search'); |
25
|
|
|
|
26
|
|
|
$rootNode->children()->booleanNode('enable_update_listener')->defaultTrue(); |
27
|
|
|
$rootNode->children()->booleanNode('use_match_query_for_title')->defaultFalse(); |
28
|
|
|
|
29
|
|
|
/** @var ArrayNodeDefinition $properties */ |
30
|
|
|
$properties = $rootNode->children()->arrayNode('mapping')->useAttributeAsKey('name')->prototype('array'); |
31
|
|
|
|
32
|
|
|
$types = [ |
33
|
|
|
'token_count', 'text', 'keyword', |
34
|
|
|
'float', 'double', 'byte', 'short', 'integer', 'long', |
35
|
|
|
'date', |
36
|
|
|
'boolean', |
37
|
|
|
'binary', |
38
|
|
|
]; |
39
|
|
|
if (!ElasticSearchUtil::useVersion6()) { |
40
|
|
|
$types[] = 'string'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$properties->children()->scalarNode('type')->beforeNormalization()->ifNotInArray($types)->thenInvalid('type must be one of: ' . implode(', ', $types)); |
44
|
|
|
|
45
|
|
|
if (ElasticSearchUtil::useVersion6()) { |
46
|
|
|
$properties->children()->booleanNode('fielddata'); |
47
|
|
|
$properties->children()->booleanNode('doc_values'); |
48
|
|
|
$properties->children() |
49
|
|
|
->scalarNode('index') |
50
|
|
|
->beforeNormalization() |
51
|
|
|
->ifNotInArray(['true', 'false', true, false]) |
52
|
|
|
->thenInvalid("index must be one of: true, false"); |
53
|
|
|
} else { |
54
|
|
|
$properties->children() |
55
|
|
|
->scalarNode('index') |
56
|
|
|
->beforeNormalization() |
57
|
|
|
->ifNotInArray(['analyzed', 'not_analyzed', 'no']) |
58
|
|
|
->thenInvalid("index must be one of: analyzed, not_analyzed, no"); |
59
|
|
|
$properties->children()->booleanNode('include_in_all'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$properties->children()->booleanNode('store'); |
63
|
|
|
$properties->children()->floatNode('boost'); |
64
|
|
|
$properties->children()->scalarNode('null_value'); |
65
|
|
|
$properties->children()->scalarNode('analyzer'); |
66
|
|
|
$properties->children()->scalarNode('search_analyzer'); |
67
|
|
|
$properties->children()->scalarNode('index_analyzer'); |
68
|
|
|
$properties->children()->scalarNode('copy_to'); |
69
|
|
|
$properties->children()->scalarNode('term_vector')->beforeNormalization()->ifNotInArray(['yes', 'no', 'with_positions', 'with_offsets', 'with_positions_offsets']) |
70
|
|
|
->thenInvalid("term_vector must be one of: yes, no, with_positions, with_offsets, with_positions_offsets"); |
71
|
|
|
|
72
|
|
|
$rootNode |
73
|
|
|
->children() |
74
|
|
|
->arrayNode('contexts') |
75
|
|
|
->defaultValue([]) |
76
|
|
|
->prototype('scalar')->end() |
77
|
|
|
->end(); |
78
|
|
|
|
79
|
|
|
return $treeBuilder; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|