Skip to content

Commit 60fb0e2

Browse files
committed
AC-6714: Fixed static and integration test failures
1 parent 3f2e4a0 commit 60fb0e2

File tree

2 files changed

+89
-88
lines changed

2 files changed

+89
-88
lines changed

app/code/Magento/Elasticsearch8/Model/Client/Elasticsearch.php

Lines changed: 88 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -120,67 +120,6 @@ public function testConnection(): bool
120120
return $this->ping();
121121
}
122122

123-
/**
124-
* Build config for Elasticsearch 8
125-
*
126-
* @param array $options
127-
* @return array
128-
*/
129-
private function buildESConfig(array $options = []): array
130-
{
131-
$hostname = preg_replace('/http[s]?:\/\//i', '', $options['hostname']);
132-
// @codingStandardsIgnoreStart
133-
$protocol = parse_url($options['hostname'], PHP_URL_SCHEME);
134-
// @codingStandardsIgnoreEnd
135-
if (!$protocol) {
136-
$protocol = 'http';
137-
}
138-
139-
$authString = '';
140-
if (!empty($options['enableAuth']) && (int)$options['enableAuth'] === 1) {
141-
$authString = "{$options['username']}:{$options['password']}@";
142-
}
143-
144-
$portString = '';
145-
if (!empty($options['port'])) {
146-
$portString = ':' . $options['port'];
147-
}
148-
149-
$host = $protocol . '://' . $authString . $hostname . $portString;
150-
151-
$options['hosts'] = [$host];
152-
153-
return $options;
154-
}
155-
156-
/**
157-
* Performs bulk query over Elasticsearch 8 index
158-
*
159-
* @param array $query
160-
* @return void
161-
*/
162-
public function bulkQuery(array $query)
163-
{
164-
$this->getElasticsearchClient()->bulk($query);
165-
}
166-
167-
/**
168-
* Creates an Elasticsearch 8 index.
169-
*
170-
* @param string $index
171-
* @param array $settings
172-
* @return void
173-
*/
174-
public function createIndex(string $index, array $settings)
175-
{
176-
$this->getElasticsearchClient()->indices()->create(
177-
[
178-
'index' => $index,
179-
'body' => $settings,
180-
]
181-
);
182-
}
183-
184123
/**
185124
* Add/update an Elasticsearch index settings.
186125
*
@@ -198,33 +137,6 @@ public function putIndexSettings(string $index, array $settings): void
198137
);
199138
}
200139

201-
/**
202-
* Delete an Elasticsearch 8 index.
203-
*
204-
* @param string $index
205-
* @return void
206-
*/
207-
public function deleteIndex(string $index)
208-
{
209-
$this->getElasticsearchClient()->indices()->delete(['index' => $index]);
210-
}
211-
212-
/**
213-
* Check if index is empty.
214-
*
215-
* @param string $index
216-
* @return bool
217-
*/
218-
public function isEmptyIndex(string $index): bool
219-
{
220-
$stats = $this->getElasticsearchClient()->indices()->stats(['index' => $index, 'metric' => 'docs']);
221-
if ($stats['indices'][$index]['primaries']['docs']['count'] === 0) {
222-
return true;
223-
}
224-
225-
return false;
226-
}
227-
228140
/**
229141
* Updates alias.
230142
*
@@ -258,6 +170,39 @@ public function indexExists(string $index): bool
258170
return $this->getElasticsearchClient()->indices()->exists(['index' => $index])->asBool();
259171
}
260172

173+
/**
174+
* Build config for Elasticsearch 8
175+
*
176+
* @param array $options
177+
* @return array
178+
*/
179+
private function buildESConfig(array $options = []): array
180+
{
181+
$hostname = preg_replace('/http[s]?:\/\//i', '', $options['hostname']);
182+
// @codingStandardsIgnoreStart
183+
$protocol = parse_url($options['hostname'], PHP_URL_SCHEME);
184+
// @codingStandardsIgnoreEnd
185+
if (!$protocol) {
186+
$protocol = 'http';
187+
}
188+
189+
$authString = '';
190+
if (!empty($options['enableAuth']) && (int)$options['enableAuth'] === 1) {
191+
$authString = "{$options['username']}:{$options['password']}@";
192+
}
193+
194+
$portString = '';
195+
if (!empty($options['port'])) {
196+
$portString = ':' . $options['port'];
197+
}
198+
199+
$host = $protocol . '://' . $authString . $hostname . $portString;
200+
201+
$options['hosts'] = [$host];
202+
203+
return $options;
204+
}
205+
261206
/**
262207
* Exists alias.
263208
*
@@ -274,6 +219,34 @@ public function existsAlias(string $alias, string $index = '')
274219
return $this->getElasticsearchClient()->indices()->existsAlias($params)->asBool();
275220
}
276221

222+
/**
223+
* Performs bulk query over Elasticsearch 8 index
224+
*
225+
* @param array $query
226+
* @return void
227+
*/
228+
public function bulkQuery(array $query)
229+
{
230+
$this->getElasticsearchClient()->bulk($query);
231+
}
232+
233+
/**
234+
* Creates an Elasticsearch 8 index.
235+
*
236+
* @param string $index
237+
* @param array $settings
238+
* @return void
239+
*/
240+
public function createIndex(string $index, array $settings)
241+
{
242+
$this->getElasticsearchClient()->indices()->create(
243+
[
244+
'index' => $index,
245+
'body' => $settings,
246+
]
247+
);
248+
}
249+
277250
/**
278251
* Get alias.
279252
*
@@ -311,6 +284,33 @@ public function addFieldsMapping(array $fields, string $index, string $entityTyp
311284
$this->getElasticsearchClient()->indices()->putMapping($params);
312285
}
313286

287+
/**
288+
* Delete an Elasticsearch 8 index.
289+
*
290+
* @param string $index
291+
* @return void
292+
*/
293+
public function deleteIndex(string $index)
294+
{
295+
$this->getElasticsearchClient()->indices()->delete(['index' => $index]);
296+
}
297+
298+
/**
299+
* Check if index is empty.
300+
*
301+
* @param string $index
302+
* @return bool
303+
*/
304+
public function isEmptyIndex(string $index): bool
305+
{
306+
$stats = $this->getElasticsearchClient()->indices()->stats(['index' => $index, 'metric' => 'docs']);
307+
if ($stats['indices'][$index]['primaries']['docs']['count'] === 0) {
308+
return true;
309+
}
310+
311+
return false;
312+
}
313+
314314
/**
315315
* Execute search by $query
316316
*

dev/tests/integration/testsuite/Magento/Elasticsearch/Controller/QuickSearchTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public function testQuickSearchWithImprovedPriceRangeCalculation()
4848
* @magentoAppArea frontend
4949
* @magentoDbIsolation disabled
5050
* @magentoConfigFixture current_store catalog/search/elasticsearch7_minimum_should_match 100%
51+
* @magentoConfigFixture current_store catalog/search/elasticsearch8_minimum_should_match 100%
5152
* @magentoConfigFixture current_store catalog/search/opensearch_minimum_should_match 100%
5253
* @magentoDataFixture Magento/Elasticsearch/_files/products_for_search.php
5354
* @magentoDataFixture Magento/CatalogSearch/_files/full_reindex.php

0 commit comments

Comments
 (0)