1 | <?php |
||
58 | class ElasticSearchPlatform implements IFullTextSearchPlatform { |
||
59 | |||
60 | |||
61 | use TPathTools; |
||
62 | |||
63 | |||
64 | /** @var ConfigService */ |
||
65 | private $configService; |
||
66 | |||
67 | /** @var IndexService */ |
||
68 | private $indexService; |
||
69 | |||
70 | /** @var SearchService */ |
||
71 | private $searchService; |
||
72 | |||
73 | /** @var MiscService */ |
||
74 | private $miscService; |
||
75 | |||
76 | /** @var Client */ |
||
77 | private $client; |
||
78 | |||
79 | /** @var IRunner */ |
||
80 | private $runner; |
||
81 | |||
82 | |||
83 | /** |
||
84 | * ElasticSearchPlatform constructor. |
||
85 | * |
||
86 | * @param ConfigService $configService |
||
87 | * @param IndexService $indexService |
||
88 | * @param SearchService $searchService |
||
89 | * @param MiscService $miscService |
||
90 | */ |
||
91 | public function __construct( |
||
100 | |||
101 | |||
102 | /** |
||
103 | * return a unique Id of the platform. |
||
104 | */ |
||
105 | public function getId(): string { |
||
108 | |||
109 | |||
110 | /** |
||
111 | * return a unique Id of the platform. |
||
112 | */ |
||
113 | public function getName(): string { |
||
116 | |||
117 | |||
118 | /** |
||
119 | * @return array |
||
120 | * @throws ConfigurationException |
||
121 | */ |
||
122 | public function getConfiguration(): array { |
||
144 | |||
145 | |||
146 | /** |
||
147 | * @param IRunner $runner |
||
148 | */ |
||
149 | public function setRunner(IRunner $runner) { |
||
152 | |||
153 | |||
154 | /** |
||
155 | * Called when loading the platform. |
||
156 | * |
||
157 | * Loading some container and connect to ElasticSearch. |
||
158 | * |
||
159 | * @throws ConfigurationException |
||
160 | * @throws Exception |
||
161 | */ |
||
162 | public function loadPlatform() { |
||
169 | |||
170 | |||
171 | /** |
||
172 | * not used yet. |
||
173 | * |
||
174 | * @return bool |
||
175 | */ |
||
176 | public function testPlatform(): bool { |
||
179 | |||
180 | |||
181 | /** |
||
182 | * called before any index |
||
183 | * |
||
184 | * We create a general index. |
||
185 | * |
||
186 | * @throws ConfigurationException |
||
187 | * @throws BadRequest400Exception |
||
188 | */ |
||
189 | public function initializeIndex() { |
||
192 | |||
193 | |||
194 | /** |
||
195 | * resetIndex(); |
||
196 | * |
||
197 | * Called when admin wants to remove an index specific to a $provider. |
||
198 | * $provider can be null, meaning a reset of the whole index. |
||
199 | * |
||
200 | * @param string $providerId |
||
201 | * |
||
202 | * @throws ConfigurationException |
||
203 | */ |
||
204 | public function resetIndex(string $providerId) { |
||
211 | |||
212 | |||
213 | /** |
||
214 | * @param IndexDocument $document |
||
215 | * |
||
216 | * @return IIndex |
||
217 | */ |
||
218 | public function indexDocument(IndexDocument $document): IIndex { |
||
262 | |||
263 | |||
264 | /** |
||
265 | * @param IndexDocument $document |
||
266 | * @param Exception $e |
||
267 | * |
||
268 | * @return array |
||
269 | * @throws AccessIsEmptyException |
||
270 | * @throws ConfigurationException |
||
271 | * @throws \Exception |
||
272 | */ |
||
273 | private function indexDocumentError(IndexDocument $document, Exception $e): array { |
||
285 | |||
286 | |||
287 | /** |
||
288 | * @param IndexDocument $document |
||
289 | * @param Exception $e |
||
290 | */ |
||
291 | private function manageIndexErrorException(IndexDocument $document, Exception $e) { |
||
300 | |||
301 | |||
302 | /** |
||
303 | * @param Exception $e |
||
304 | * |
||
305 | * @return string |
||
306 | */ |
||
307 | private function parseIndexErrorException(Exception $e): string { |
||
320 | |||
321 | |||
322 | /** |
||
323 | * {@inheritdoc} |
||
324 | * @throws ConfigurationException |
||
325 | */ |
||
326 | public function deleteIndexes(array $indexes) { |
||
333 | |||
334 | |||
335 | /** |
||
336 | * {@inheritdoc} |
||
337 | * @throws Exception |
||
338 | */ |
||
339 | public function searchRequest(ISearchResult $result, DocumentAccess $access) { |
||
342 | |||
343 | |||
344 | /** |
||
345 | * @param string $providerId |
||
346 | * @param string $documentId |
||
347 | * |
||
348 | * @return IndexDocument |
||
349 | * @throws ConfigurationException |
||
350 | */ |
||
351 | public function getDocument(string $providerId, string $documentId): IndexDocument { |
||
354 | |||
355 | |||
356 | private function cleanHost($host) { |
||
359 | |||
360 | /** |
||
361 | * @param array $hosts |
||
362 | * |
||
363 | * @throws Exception |
||
364 | */ |
||
365 | private function connectToElastic(array $hosts) { |
||
386 | |||
387 | |||
388 | /** |
||
389 | * @param string $action |
||
390 | * @param bool $force |
||
391 | * |
||
392 | * @throws Exception |
||
393 | */ |
||
394 | private function updateRunnerAction(string $action, bool $force = false) { |
||
401 | |||
402 | |||
403 | /** |
||
404 | * @param IIndex $index |
||
405 | * @param string $message |
||
406 | * @param string $exception |
||
407 | * @param int $sev |
||
408 | */ |
||
409 | private function updateNewIndexError(IIndex $index, string $message, string $exception, int $sev |
||
417 | |||
418 | |||
419 | /** |
||
420 | * @param IIndex $index |
||
421 | * @param string $message |
||
422 | * @param string $status |
||
423 | * @param int $type |
||
424 | */ |
||
425 | private function updateNewIndexResult(IIndex $index, string $message, string $status, int $type |
||
433 | |||
434 | |||
435 | } |
||
436 |