Skip to content

Commit 713f7c8

Browse files
committed
Merge branch 'ACP2E-3521' of https://github.com/adobe-commerce-tier-4/magento2ce into PR-VK-2024-12-17-CE
2 parents c3c90c7 + f3b10b9 commit 713f7c8

File tree

7 files changed

+67
-50
lines changed

7 files changed

+67
-50
lines changed

app/code/Magento/Elasticsearch/Model/Adapter/BatchDataMapper/ProductDataMapper.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2017 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\Elasticsearch\Model\Adapter\BatchDataMapper;
@@ -22,6 +22,8 @@
2222
*/
2323
class ProductDataMapper implements BatchDataMapperInterface
2424
{
25+
private const MAX_STRING_LENGTH = 32766;
26+
2527
/**
2628
* @var AttributeOptionInterface[]
2729
*/
@@ -315,7 +317,9 @@ function (string $valueId) {
315317
&& in_array($attribute->getAttributeCode(), $this->sortableAttributesValuesToImplode)
316318
&& count($attributeValues) > 1
317319
) {
318-
$attributeValues = [$productId => implode("\n", $attributeValues)];
320+
$attributeValues = [
321+
$productId => trim(substr(implode("\n", $attributeValues), 0, self::MAX_STRING_LENGTH)),
322+
];
319323
}
320324

321325
if (in_array($attribute->getAttributeCode(), $this->sortableCaseSensitiveAttributes)) {

app/code/Magento/Elasticsearch/Model/Adapter/Elasticsearch.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\Elasticsearch\Model\Adapter;
@@ -309,7 +309,14 @@ public function addDocs(array $documents, $storeId, $mappedIndexerId)
309309
$indexName = $this->indexNameResolver->getIndexName($storeId, $mappedIndexerId, $this->preparedIndex);
310310
$bulkIndexDocuments = $this->getDocsArrayInBulkIndexFormat($documents, $indexName);
311311
if ($this->isStackQueries === false) {
312-
$this->client->bulkQuery($bulkIndexDocuments);
312+
$result = $this->client->bulkQuery($bulkIndexDocuments);
313+
if ($result['errors']) {
314+
$errors = array_filter(
315+
array_column($result['items'], 'index'),
316+
fn ($item) => isset($item['error'])
317+
);
318+
$this->logger->critical('Errors happened during catalog search reindex', $errors);
319+
}
313320
} else {
314321
$this->stackQueries($bulkIndexDocuments);
315322
}

app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/BatchDataMapper/ProductDataMapperTest.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2017 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -496,6 +496,32 @@ public static function mapProvider(): array
496496
15,
497497
[],
498498
],
499+
'sortable multiple values' => [
500+
10,
501+
[
502+
'attribute_code' => 'name',
503+
'backend_type' => 'text',
504+
'frontend_input' => 'text',
505+
'is_searchable' => true,
506+
'used_for_sort_by' => true,
507+
'options' => [],
508+
],
509+
[10 => 'one', 11 => 'two', 12 => 'three'],
510+
['name' => implode("\n", ['one', 'two', 'three'])],
511+
],
512+
'sortable too many multiple values' => [
513+
10,
514+
[
515+
'attribute_code' => 'name',
516+
'backend_type' => 'text',
517+
'frontend_input' => 'text',
518+
'is_searchable' => true,
519+
'used_for_sort_by' => true,
520+
'options' => [],
521+
],
522+
array_fill(0, 4682, '123456'),
523+
['name' => implode("\n", array_fill(0, 4681, '123456'))],
524+
],
499525
];
500526
}
501527
}

app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/ElasticsearchTest.php

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -154,14 +154,7 @@ protected function setUp(): void
154154
$elasticsearchClientMock->expects($this->any())
155155
->method('indices')
156156
->willReturn($indicesMock);
157-
$this->client = $this->getMockBuilder(Elasticsearch::class)
158-
->setConstructorArgs(
159-
[
160-
'options' => $this->getClientOptions(),
161-
'elasticsearchClient' => $elasticsearchClientMock
162-
]
163-
)
164-
->getMock();
157+
$this->client = $this->createMock(Elasticsearch::class);
165158
$this->connectionManager->expects($this->any())
166159
->method('getConnection')
167160
->willReturn($this->client);
@@ -300,7 +293,8 @@ public function testPrepareDocsPerStore(): void
300293
public function testAddDocs(): void
301294
{
302295
$this->client->expects($this->once())
303-
->method('bulkQuery');
296+
->method('bulkQuery')
297+
->willReturn(['errors' => false]);
304298
$this->assertSame(
305299
$this->model,
306300
$this->model->addDocs(
@@ -698,24 +692,6 @@ function ($arg1, $arg2) use ($settings) {
698692
$this->emulateCleanIndex();
699693
}
700694

701-
/**
702-
* Get elasticsearch client options
703-
*
704-
* @return array
705-
*/
706-
protected function getClientOptions(): array
707-
{
708-
return [
709-
'hostname' => 'localhost',
710-
'port' => '9200',
711-
'timeout' => 15,
712-
'index' => 'magento2',
713-
'enableAuth' => 1,
714-
'username' => 'user',
715-
'password' => 'my-password'
716-
];
717-
}
718-
719695
/**
720696
* Run Clean Index; Index Name Mock value should be non-nullable for PHP 8.1 compatibility
721697
*

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -168,11 +168,11 @@ private function buildESConfig(array $options = []): array
168168
* Performs bulk query over Elasticsearch 7 index
169169
*
170170
* @param array $query
171-
* @return void
171+
* @return array
172172
*/
173173
public function bulkQuery(array $query)
174174
{
175-
$this->getElasticsearchClient()->bulk($query);
175+
return $this->getElasticsearchClient()->bulk($query);
176176
}
177177

178178
/**

app/code/Magento/Elasticsearch7/Test/Unit/Model/Client/ElasticsearchTest.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
6-
76
declare(strict_types=1);
87

98
namespace Magento\Elasticsearch7\Test\Unit\Model\Client;
@@ -265,10 +264,15 @@ public function testTestConnectionPing()
265264
*/
266265
public function testBulkQuery()
267266
{
267+
$result = [
268+
'errors' => false,
269+
'items' => [],
270+
];
268271
$this->elasticsearchClientMock->expects($this->once())
269272
->method('bulk')
270-
->with([]);
271-
$this->model->bulkQuery([]);
273+
->with([])
274+
->willReturn($result);
275+
$this->assertEquals($result, $this->model->bulkQuery([]));
272276
}
273277

274278
/**

app/code/Magento/OpenSearch/Model/SearchClient.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2022 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -165,11 +165,11 @@ private function buildOSConfig(array $options = []): array
165165
* Performs bulk query over OpenSearch index
166166
*
167167
* @param array $query
168-
* @return void
168+
* @return array
169169
*/
170170
public function bulkQuery(array $query)
171171
{
172-
$this->getOpenSearchClient()->bulk($query);
172+
return $this->getOpenSearchClient()->bulk($query);
173173
}
174174

175175
/**

0 commit comments

Comments
 (0)