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 | * @throws BadRequest400Exception |
||
68 | */ |
||
69 | public function initializeIndex(Client $client) { |
||
70 | try { |
||
71 | if ($client->indices() |
||
72 | ->exists($this->indexMappingService->generateGlobalMap(false))) { |
||
73 | return; |
||
74 | } |
||
75 | } catch (BadRequest400Exception $e) { |
||
76 | $this->parseBadRequest400($e); |
||
77 | } |
||
78 | |||
79 | try { |
||
80 | $client->indices() |
||
81 | ->create($this->indexMappingService->generateGlobalMap()); |
||
82 | $client->ingest() |
||
83 | ->putPipeline($this->indexMappingService->generateGlobalIngest()); |
||
84 | } catch (BadRequest400Exception $e) { |
||
85 | $this->resetIndex($client); |
||
86 | $this->parseBadRequest400($e); |
||
87 | } |
||
88 | } |
||
89 | |||
90 | |||
91 | /** |
||
92 | * @param Client $client |
||
93 | * |
||
94 | * @throws ConfigurationException |
||
95 | */ |
||
96 | public function resetIndex(Client $client) { |
||
97 | try { |
||
98 | $client->ingest() |
||
99 | ->deletePipeline($this->indexMappingService->generateGlobalIngest(false)); |
||
100 | } catch (Missing404Exception $e) { |
||
101 | /* 404Exception will means that the mapping for that provider does not exist */ |
||
102 | } catch (BadRequest400Exception $e) { |
||
103 | throw new ConfigurationException( |
||
104 | 'Check your user/password and the index assigned to that cloud' |
||
105 | ); |
||
106 | } |
||
107 | |||
108 | try { |
||
109 | $client->indices() |
||
110 | ->delete($this->indexMappingService->generateGlobalMap(false)); |
||
111 | } catch (Missing404Exception $e) { |
||
112 | /* 404Exception will means that the mapping for that provider does not exist */ |
||
113 | } |
||
114 | } |
||
115 | |||
116 | |||
117 | /** |
||
118 | * @param Client $client |
||
119 | * @param Index[] $indexes |
||
120 | * |
||
121 | * @throws ConfigurationException |
||
122 | */ |
||
123 | public function deleteIndexes($client, $indexes) { |
||
124 | foreach ($indexes as $index) { |
||
125 | $this->indexMappingService->indexDocumentRemove( |
||
126 | $client, $index->getProviderId(), $index->getDocumentId() |
||
127 | ); |
||
128 | } |
||
129 | } |
||
130 | |||
131 | |||
132 | /** |
||
133 | * @param IFullTextSearchPlatform $platform |
||
134 | * @param Client $client |
||
135 | * @param IFullTextSearchProvider $provider |
||
136 | * @param IndexDocument $document |
||
137 | * |
||
138 | * @return array |
||
|
|||
139 | * @throws ConfigurationException |
||
140 | * @throws AccessIsEmptyException |
||
141 | */ |
||
142 | public function indexDocument( |
||
163 | |||
164 | |||
165 | /** |
||
166 | * @param Index $index |
||
167 | * @param array $result |
||
168 | * |
||
169 | * @return Index |
||
170 | */ |
||
171 | public function parseIndexResult(Index $index, array $result) { |
||
188 | |||
189 | |||
190 | /** |
||
191 | * @param BadRequest400Exception $e |
||
192 | * |
||
193 | * @throws ConfigurationException |
||
194 | * @throws BadRequest400Exception |
||
195 | */ |
||
196 | private function parseBadRequest400(BadRequest400Exception $e) { |
||
217 | |||
218 | } |
||
219 |
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>
.