Skip to content

Commit bea3db3

Browse files
committed
Merge remote-tracking branch 'origin/ACP2E-3897' into PR_2025_08_25_muntianu
2 parents 3026734 + e8f9713 commit bea3db3

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

app/code/Magento/CatalogGraphQl/DataProvider/Product/SearchCriteriaBuilder.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class SearchCriteriaBuilder
3838
* @param RequestDataBuilder $localData
3939
* @param SearchCriteriaResolverFactory $criteriaResolverFactory
4040
* @param ArgumentApplierPool $argumentApplierPool
41+
* @param array $partialSearchAnalyzers
4142
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
4243
*/
4344
public function __construct(
@@ -51,6 +52,7 @@ public function __construct(
5152
private readonly RequestDataBuilder $localData,
5253
private readonly SearchCriteriaResolverFactory $criteriaResolverFactory,
5354
private readonly ArgumentApplierPool $argumentApplierPool,
55+
private readonly array $partialSearchAnalyzers = []
5456
) {
5557
}
5658

@@ -117,6 +119,10 @@ private function updateMatchTypeRequestConfig(string $requestName, array $partia
117119
foreach ($query['match'] ?? [] as $index => $matchItem) {
118120
if (in_array($matchItem['field'] ?? null, $partialMatchFilters, true)) {
119121
$data['queries'][$queryName]['match'][$index]['matchCondition'] = 'match_phrase_prefix';
122+
if (array_key_exists($matchItem['field'], $this->partialSearchAnalyzers)) {
123+
$data['queries'][$queryName]['match'][$index]['analyzer']
124+
= $this->partialSearchAnalyzers[$matchItem['field']];
125+
}
120126
}
121127
}
122128
}

app/code/Magento/CatalogGraphQl/etc/di.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,12 @@
150150
</argument>
151151
</arguments>
152152
</type>
153+
154+
<type name="Magento\CatalogGraphQl\DataProvider\Product\SearchCriteriaBuilder">
155+
<arguments>
156+
<argument name="partialSearchAnalyzers" xsi:type="array">
157+
<item name="name" xsi:type="string">prefix_search</item>
158+
</argument>
159+
</arguments>
160+
</type>
153161
</config>

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductSearchTest.php

Lines changed: 60 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

@@ -204,6 +204,64 @@ public function sortByPriceAndNameDataProvider(): array
204204
];
205205
}
206206

207+
/**
208+
* @dataProvider filterByNameWithMatchTypeSpecifiedDataProvider
209+
*/
210+
#[
211+
DataFixture(ProductFixture::class, ['price' => 10, 'name' => 'Cronus Yoga Pant'], 'prod1'),
212+
DataFixture(ProductFixture::class, ['price' => 10, 'name' => 'Lucia Cross-Fit Bra'], 'prod2'),
213+
DataFixture(ProductFixture::class, ['price' => 20, 'name' => 'Crown Summit Backpack'], 'prod3'),
214+
]
215+
public function testFilterByNameWithMatchTypeSpecified($matchType, $expectedReturns, $expectedTotalCount): void
216+
{
217+
$expectedNames = [];
218+
foreach ($expectedReturns as $productName) {
219+
$expectedNames[] = $this->fixture->get($productName)->getName();
220+
}
221+
$query = <<<'QUERY'
222+
query GetProductsQuery(
223+
$searchWord: String,
224+
$matchType: FilterMatchTypeEnum
225+
) {
226+
products(
227+
filter: {name: {match: $searchWord, match_type: $matchType} },
228+
) {
229+
total_count
230+
page_info{total_pages}
231+
items{
232+
__typename
233+
url_key
234+
sku
235+
name
236+
}
237+
}
238+
}
239+
QUERY;
240+
$variables = [
241+
'searchWord' => 'Cros',
242+
'matchType' => $matchType,
243+
];
244+
245+
$response = $this->graphQlQuery($query, $variables);
246+
$this->assertArrayNotHasKey('errors', $response);
247+
$this->assertEquals($expectedTotalCount, $response['products']['total_count']);
248+
$this->assertEquals($expectedNames, array_column($response['products']['items'], 'name'));
249+
}
250+
251+
/**
252+
* @return array
253+
*/
254+
public function filterByNameWithMatchTypeSpecifiedDataProvider(): array
255+
{
256+
return [
257+
[
258+
'PARTIAL',
259+
['prod2'],
260+
1
261+
],
262+
];
263+
}
264+
207265
/**
208266
* Verify that filters for non-existing category are empty
209267
*

0 commit comments

Comments
 (0)