Skip to content

Commit a0f3c9b

Browse files
author
Prabhu Ram
committed
MC-33710: Elasticsearch configuration fields are out of order
- Added partial search for "name" field
1 parent def8a07 commit a0f3c9b

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

app/code/Magento/CatalogSearch/etc/search_request.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@
1414
<queries>
1515
<query xsi:type="boolQuery" name="quick_search_container" boost="1">
1616
<queryReference clause="should" ref="search" />
17+
<queryReference clause="should" ref="partial_search" />
1718
<queryReference clause="must" ref="category"/>
1819
<queryReference clause="must" ref="price"/>
1920
<queryReference clause="must" ref="visibility"/>
2021
</query>
2122
<query xsi:type="matchQuery" value="$search_term$" name="search">
2223
<match field="*"/>
2324
</query>
25+
<query xsi:type="matchQuery" value="$search_term$" name="partial_search">
26+
<match field="name" matchCondition="match_phrase_prefix"/>
27+
</query>
2428
<query xsi:type="filteredQuery" name="category">
2529
<filterReference clause="must" ref="category_filter"/>
2630
</query>

app/code/Magento/Elasticsearch/SearchAdapter/Query/Builder/Match.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function build(array $selectQuery, RequestQueryInterface $requestQuery, $
8080
$minimumShouldMatch = $this->config->getElasticsearchConfigData('minimum_should_match');
8181
foreach ($queries as $query) {
8282
$queryBody = $query['body'];
83-
$matchKey = isset($queryBody['match_phrase']) ? 'match_phrase' : 'match';
83+
$matchKey = array_keys($queryBody)[0];
8484
foreach ($queryBody[$matchKey] as $field => $matchQuery) {
8585
$matchQuery['boost'] = $requestQueryBoost + $matchQuery['boost'];
8686
if ($minimumShouldMatch) {
@@ -132,7 +132,7 @@ protected function buildQueries(array $matches, array $queryValue)
132132
// Checking for quoted phrase \"phrase test\", trim escaped surrounding quotes if found
133133
$count = 0;
134134
$value = preg_replace('#^"(.*)"$#m', '$1', $queryValue['value'], -1, $count);
135-
$condition = ($count) ? 'match_phrase' : 'match';
135+
$matchCondition = ($count) ? 'match_phrase' : 'match';
136136

137137
$transformedTypes = [];
138138
foreach ($matches as $match) {
@@ -153,11 +153,11 @@ protected function buildQueries(array $matches, array $queryValue)
153153
//Value is incompatible with this field type.
154154
continue;
155155
}
156-
156+
$matchCondition = $match['matchCondition'] ?? $matchCondition;
157157
$conditions[] = [
158158
'condition' => $queryValue['condition'],
159159
'body' => [
160-
$condition => [
160+
$matchCondition => [
161161
$resolvedField => [
162162
'query' => $transformedValue,
163163
'boost' => $match['boost'] ?? 1,

lib/internal/Magento/Framework/Search/etc/requests.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@
225225
<xs:simpleContent>
226226
<xs:extension base="xs:string">
227227
<xs:attribute type="xs:string" name="field" use="required" />
228+
<xs:attribute type="xs:string" name="matchCondition" />
228229
</xs:extension>
229230
</xs:simpleContent>
230231
</xs:complexType>

0 commit comments

Comments
 (0)