1 | <?php |
||
39 | class IndexService { |
||
40 | |||
41 | |||
42 | /** @var IndexMappingService */ |
||
43 | private $indexMappingService; |
||
44 | |||
45 | /** @var MiscService */ |
||
46 | private $miscService; |
||
47 | |||
48 | |||
49 | /** |
||
50 | * IndexService constructor. |
||
51 | * |
||
52 | * @param IndexMappingService $indexMappingService |
||
53 | * @param MiscService $miscService |
||
54 | */ |
||
55 | public function __construct( |
||
56 | IndexMappingService $indexMappingService, MiscService $miscService |
||
57 | ) { |
||
58 | $this->indexMappingService = $indexMappingService; |
||
59 | $this->miscService = $miscService; |
||
60 | } |
||
61 | |||
62 | |||
63 | /** |
||
64 | * @param Client $client |
||
65 | * |
||
66 | * @throws ConfigurationException |
||
67 | */ |
||
68 | public function initializeIndex(Client $client) { |
||
69 | try { |
||
70 | $result = $client->indices() |
||
71 | ->exists($this->indexMappingService->generateGlobalMap(false)); |
||
72 | } catch (BadRequest400Exception $e) { |
||
73 | throw new ConfigurationException( |
||
74 | 'Check your user/password and the index assigned to that cloud' |
||
75 | ); |
||
76 | } |
||
77 | |||
78 | try { |
||
79 | if (!$result) { |
||
80 | $client->indices() |
||
81 | ->create($this->indexMappingService->generateGlobalMap()); |
||
82 | $client->ingest() |
||
83 | ->putPipeline($this->indexMappingService->generateGlobalIngest()); |
||
84 | } |
||
85 | } catch (BadRequest400Exception $e) { |
||
86 | $this->resetIndex($client); |
||
87 | $this->parseBadRequest400($e); |
||
88 | } |
||
89 | } |
||
90 | |||
91 | |||
92 | /** |
||
93 | * @param Client $client |
||
94 | * |
||
95 | * @throws ConfigurationException |
||
96 | */ |
||
97 | public function resetIndex(Client $client) { |
||
116 | |||
117 | |||
118 | /** |
||
119 | * @param Client $client |
||
120 | * @param Index[] $indexes |
||
121 | * |
||
122 | * @throws ConfigurationException |
||
123 | */ |
||
124 | public function deleteIndexes($client, $indexes) { |
||
131 | |||
132 | |||
133 | /** |
||
134 | * @param IFullTextSearchPlatform $platform |
||
135 | * @param Client $client |
||
136 | * @param IFullTextSearchProvider $provider |
||
137 | * @param IndexDocument $document |
||
138 | * |
||
139 | * @return array |
||
|
|||
140 | * @throws ConfigurationException |
||
141 | * @throws AccessIsEmptyException |
||
142 | */ |
||
143 | public function indexDocument( |
||
164 | |||
165 | |||
166 | /** |
||
167 | * @param Index $index |
||
168 | * @param array $result |
||
169 | * |
||
170 | * @return Index |
||
171 | */ |
||
172 | public function parseIndexResult(Index $index, array $result) { |
||
189 | |||
190 | |||
191 | /** |
||
192 | * @param BadRequest400Exception $e |
||
193 | * |
||
194 | * @throws ConfigurationException |
||
195 | */ |
||
196 | private function parseBadRequest400(BadRequest400Exception $e) { |
||
209 | |||
210 | } |
||
211 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.If the return type contains the type array, this check recommends the use of a more specific type like
String[]
orarray<String>
.