1 | <?php |
||
16 | class IndexService |
||
17 | { |
||
18 | /** |
||
19 | * @var \Elastica\Client |
||
20 | */ |
||
21 | protected $client; |
||
22 | |||
23 | /** |
||
24 | * @var Index |
||
25 | */ |
||
26 | private $index; |
||
27 | |||
28 | /** |
||
29 | * @var \Psr\Log\LoggerInterface |
||
30 | */ |
||
31 | private $logger; |
||
32 | |||
33 | /** |
||
34 | * @var \T3G\Elasticorn\Service\ConfigurationService |
||
35 | */ |
||
36 | private $configurationService; |
||
37 | |||
38 | /** |
||
39 | * IndexService constructor. |
||
40 | * |
||
41 | * @param \Elastica\Client $client |
||
42 | * @param \T3G\Elasticorn\Service\ConfigurationService $configurationService |
||
43 | * @param \Psr\Log\LoggerInterface $logger |
||
44 | * @param string $indexName |
||
45 | */ |
||
46 | public function __construct( |
||
59 | |||
60 | /** |
||
61 | * @return Index|null |
||
62 | */ |
||
63 | public function getIndex() |
||
67 | |||
68 | /** |
||
69 | * Rename an index (creates new index with data from old) |
||
70 | * CAUTION: All mappings are lost, only data is preserved |
||
71 | * |
||
72 | * @param string $newName |
||
73 | */ |
||
74 | public function renameIndex(string $newName) |
||
82 | |||
83 | /** |
||
84 | * Add all indices found in configuration directory |
||
85 | * Creates indices with suffixes _a and _b and adds an alias as indexName |
||
86 | */ |
||
87 | public function initIndices() |
||
94 | |||
95 | /** |
||
96 | * Initializes a single index from config files |
||
97 | * |
||
98 | * @param string $indexName |
||
99 | */ |
||
100 | public function initIndex(string $indexName) |
||
106 | |||
107 | /** |
||
108 | * Copy data from oldIndexName to newIndexName |
||
109 | * |
||
110 | * @param string $oldIndexName |
||
111 | * @param string $newIndexName |
||
112 | */ |
||
113 | public function copyData(string $oldIndexName, string $newIndexName) |
||
120 | |||
121 | /** |
||
122 | * Re-apply mappings to all indices found in configuration directory |
||
123 | * |
||
124 | * @see remap($indexName) |
||
125 | * |
||
126 | * @param bool $force |
||
127 | */ |
||
128 | public function remapAll(bool $force = false) |
||
136 | |||
137 | /** |
||
138 | * @return array |
||
139 | */ |
||
140 | public function getMappingForIndex() |
||
145 | |||
146 | |||
147 | /** |
||
148 | * Remap an index |
||
149 | * |
||
150 | * Drops and recreates the current inactive index, applies mappings and imports data from active index |
||
151 | * After successfully importing data the alias gets set to the new index |
||
152 | * |
||
153 | * @param string $indexName |
||
154 | * @param bool $force |
||
155 | * |
||
156 | * @throws \InvalidArgumentException |
||
157 | */ |
||
158 | public function remap(string $indexName, bool $force = false) |
||
181 | |||
182 | /** |
||
183 | * @param string $indexName |
||
184 | */ |
||
185 | private function remapIndex(string $indexName, string $language = '') |
||
220 | |||
221 | /** |
||
222 | * @param string $indexName |
||
223 | * @param \Elastica\Index $activeIndex |
||
224 | * @param \Elastica\Index $inactiveIndex |
||
225 | */ |
||
226 | private function switchAlias(string $indexName, Index $activeIndex, Index $inactiveIndex) |
||
232 | |||
233 | /** |
||
234 | * @param string $indexName |
||
235 | * @param array $configuration |
||
236 | * |
||
237 | * @throws \InvalidArgumentException |
||
238 | */ |
||
239 | private function createIndex(string $indexName, array $configuration) |
||
260 | |||
261 | private function createPrimaryIndex(string $indexName, array $configuration, string $language = '') |
||
267 | |||
268 | /** |
||
269 | * @param string $indexName |
||
270 | * @param array $configuration |
||
271 | * @param string $language |
||
272 | */ |
||
273 | private function createSecondaryIndex(string $indexName, array $configuration, string $language = '') |
||
278 | |||
279 | private function getFullIndexIdentifier(string $indexName, string $suffix = '', string $language = '') |
||
283 | |||
284 | /** |
||
285 | * @param string $indexName |
||
286 | * @param \Elastica\Index $index |
||
287 | * @param $indexConfiguration |
||
288 | */ |
||
289 | private function createWithMapping( |
||
299 | |||
300 | /** |
||
301 | * @param string $indexName |
||
302 | * @param Index $index |
||
303 | * @param string $language |
||
304 | */ |
||
305 | private function recreateIndex(string $indexName, Index $index, string $language) |
||
312 | } |
||
313 |