|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the FOSElasticaBundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* This file is part of the FOSElasticaBundle project. |
|
14
|
|
|
* |
|
15
|
|
|
* (c) Tim Nagel <[email protected]> |
|
16
|
|
|
* |
|
17
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
18
|
|
|
* file that was distributed with this source code. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace FOS\ElasticaBundle\Configuration; |
|
22
|
|
|
|
|
23
|
|
|
class IndexConfig |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* The name of the index for ElasticSearch. |
|
27
|
|
|
* |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
private $elasticSearchName; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* The internal name of the index. May not be the same as the name used in ElasticSearch, |
|
34
|
|
|
* especially if aliases are enabled. |
|
35
|
|
|
* |
|
36
|
|
|
* @var string |
|
37
|
|
|
*/ |
|
38
|
|
|
private $name; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* An array of settings sent to ElasticSearch when creating the index. |
|
42
|
|
|
* |
|
43
|
|
|
* @var array |
|
44
|
|
|
*/ |
|
45
|
|
|
private $settings; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* All types that belong to this index. |
|
49
|
|
|
* |
|
50
|
|
|
* @var TypeConfig[] |
|
51
|
|
|
*/ |
|
52
|
|
|
private $types; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Indicates if the index should use an alias, allowing an index repopulation to occur |
|
56
|
|
|
* without overwriting the current index. |
|
57
|
|
|
* |
|
58
|
|
|
* @var bool |
|
59
|
|
|
*/ |
|
60
|
|
|
private $useAlias = false; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Constructor expects an array as generated by the Container Configuration builder. |
|
64
|
|
|
* |
|
65
|
|
|
* @param string $name |
|
66
|
|
|
* @param TypeConfig[] $types |
|
67
|
|
|
* @param array $config |
|
68
|
|
|
*/ |
|
69
|
|
|
public function __construct($name, array $types, array $config) |
|
70
|
|
|
{ |
|
71
|
|
|
$this->elasticSearchName = isset($config['elasticSearchName']) ? $config['elasticSearchName'] : $name; |
|
72
|
|
|
$this->name = $name; |
|
73
|
|
|
$this->settings = isset($config['settings']) ? $config['settings'] : []; |
|
74
|
|
|
$this->types = $types; |
|
75
|
|
|
$this->useAlias = isset($config['useAlias']) ? $config['useAlias'] : false; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @return string |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getElasticSearchName() |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->elasticSearchName; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @return string |
|
88
|
|
|
*/ |
|
89
|
|
|
public function getName() |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->name; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return array |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getSettings() |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->settings; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @param string $typeName |
|
104
|
|
|
* |
|
105
|
|
|
* @return TypeConfig |
|
106
|
|
|
* |
|
107
|
|
|
* @throws \InvalidArgumentException |
|
108
|
|
|
*/ |
|
109
|
|
|
public function getType($typeName) |
|
110
|
|
|
{ |
|
111
|
|
|
if (!array_key_exists($typeName, $this->types)) { |
|
112
|
|
|
throw new \InvalidArgumentException(sprintf('Type "%s" does not exist on index "%s"', $typeName, $this->name)); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
return $this->types[$typeName]; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @return \FOS\ElasticaBundle\Configuration\TypeConfig[] |
|
120
|
|
|
*/ |
|
121
|
|
|
public function getTypes() |
|
122
|
|
|
{ |
|
123
|
|
|
return $this->types; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @return bool |
|
128
|
|
|
*/ |
|
129
|
|
|
public function isUseAlias() |
|
130
|
|
|
{ |
|
131
|
|
|
return $this->useAlias; |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|