Skip to content

Commit 00d4476

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-44555' into BugFestW4
2 parents e05f432 + 2d24398 commit 00d4476

File tree

11 files changed

+30
-23
lines changed

11 files changed

+30
-23
lines changed

app/code/Magento/CatalogSearch/Model/Advanced.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ public function __construct(
166166
public function addFilters($values)
167167
{
168168
$attributes = $this->getAttributes();
169-
$hasConditions = false;
170169
$allConditions = [];
171170

172171
foreach ($attributes as $attribute) {
@@ -225,7 +224,7 @@ public function addFilters($values)
225224
if ($allConditions) {
226225
$this->_registry->register('advanced_search_conditions', $allConditions);
227226
$this->getProductCollection()->addFieldsToFilter($allConditions);
228-
} elseif (!$hasConditions) {
227+
} else {
229228
throw new LocalizedException(__('Please specify at least one search term.'));
230229
}
231230

app/code/Magento/CatalogSearch/Model/Advanced/Request/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function bindRequestValue($attributeCode, $attributeValue)
2727
} elseif (!is_array($attributeValue)) {
2828
$this->bind($attributeCode, $attributeValue);
2929
} elseif (isset($attributeValue['like'])) {
30-
$this->bind($attributeCode, trim($attributeValue['like'], '%'));
30+
$this->bind($attributeCode, $attributeValue['like']);
3131
} elseif (isset($attributeValue['in'])) {
3232
$this->bind($attributeCode, $attributeValue['in']);
3333
} elseif (isset($attributeValue['in_set'])) {

app/code/Magento/CatalogSearch/Model/ResourceModel/Advanced.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function prepareCondition($attribute, $value)
8181
} else {
8282
if (strlen($value) > 0) {
8383
if (in_array($attribute->getBackendType(), ['varchar', 'text', 'static'])) {
84-
$condition = ['like' => '%' . $value . '%']; // text search
84+
$condition = ['like' => $value]; // text search
8585
} else {
8686
$condition = $value;
8787
}

app/code/Magento/CatalogSearch/Test/Unit/Model/Advanced/Request/BuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public function testCreate()
182182
];
183183
$this->requestBuilder->bindRequestValue('from_to', ['from' => 10, 'to' => 20]);
184184
$this->requestBuilder->bindRequestValue('not_array', 130);
185-
$this->requestBuilder->bindRequestValue('like', ['like' => '%search_text%']);
185+
$this->requestBuilder->bindRequestValue('like', ['like' => 'search_text']);
186186
$this->requestBuilder->bindRequestValue('in', ['in' => 23]);
187187
$this->requestBuilder->bindRequestValue('in_set', ['in_set' => [12, 23, 34, 45]]);
188188
$this->requestBuilder->setRequestName($requestName);

app/code/Magento/CatalogSearch/Test/Unit/Model/ResourceModel/AdvancedTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function prepareConditionDataProvider()
5454
{
5555
return [
5656
['string', 'string', 'string'],
57-
['varchar', 'string', ['like' => '%string%']],
57+
['varchar', 'string', ['like' => 'string']],
5858
['varchar', ['test'], ['in_set' => ['test']]],
5959
['select', ['test'], ['in' => ['test']]],
6060
['range', ['from' => 1], ['from' => 1]],

lib/internal/Magento/Framework/Search/Adapter/Mysql/Query/Builder/Match.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
class Match implements QueryInterface
1717
{
18-
const SPECIAL_CHARACTERS = '-+~/\\<>\'":*$#@()!,.?`=';
18+
const SPECIAL_CHARACTERS = '-+~/\\<>\'":*$#@()!,.?`=%&^_';
1919

2020
const MINIMAL_CHARACTER_LENGTH = 3;
2121

lib/internal/Magento/Framework/Search/Request/Binder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ private function processData($data, $bindData)
8181
} else {
8282
$data[$key] = $bindValue;
8383
}
84+
$data['is_bind'] = true;
8485
}
8586
}
8687
}

lib/internal/Magento/Framework/Search/Request/Cleaner.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private function cleanQuery($queryName)
9090
}
9191
break;
9292
case QueryInterface::TYPE_MATCH:
93-
if (preg_match('/\$(.+)\$/si', $query['value'], $matches)) {
93+
if (!array_key_exists('is_bind', $query)) {
9494
unset($this->requestData['queries'][$queryName]);
9595
}
9696
break;
@@ -131,7 +131,7 @@ private function cleanAggregations()
131131
switch ($aggregationValue['type']) {
132132
case 'dynamicBucket':
133133
if (is_string($aggregationValue['method'])
134-
&& preg_match('/\$(.+)\$/si', $aggregationValue['method'])
134+
&& preg_match('/^\$(.+)\$$/si', $aggregationValue['method'])
135135
) {
136136
unset($this->requestData['aggregations'][$aggregationName]);
137137
}
@@ -164,14 +164,14 @@ private function cleanFilter($filterName)
164164
switch ($filter['type']) {
165165
case FilterInterface::TYPE_WILDCARD:
166166
case FilterInterface::TYPE_TERM:
167-
if (is_string($filter['value']) && preg_match('/\$(.+)\$/si', $filter['value'], $matches)) {
167+
if (!array_key_exists('is_bind', $filter)) {
168168
unset($this->requestData['filters'][$filterName]);
169169
}
170170
break;
171171
case FilterInterface::TYPE_RANGE:
172172
$keys = ['from', 'to'];
173173
foreach ($keys as $key) {
174-
if (isset($filter[$key]) && preg_match('/\$(.+)\$/si', $filter[$key], $matches)) {
174+
if (isset($filter[$key]) && preg_match('/^\$(.+)\$$/si', $filter[$key])) {
175175
unset($this->requestData['filters'][$filterName][$key]);
176176
}
177177
}

lib/internal/Magento/Framework/Search/Test/Unit/Adapter/Mysql/Query/Builder/MatchTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function testBuildQuery()
6464
->getMock();
6565
$this->fulltextHelper->expects($this->once())
6666
->method('getMatchQuery')
67-
->with($this->equalTo(['some_field' => 'some_field']), $this->equalTo('-some_value*'))
67+
->with($this->equalTo(['some_field' => 'some_field']), $this->equalTo('-some* -value*'))
6868
->will($this->returnValue('matchedQuery'));
6969
$select->expects($this->once())
7070
->method('where')

lib/internal/Magento/Framework/Search/Test/Unit/Request/BinderTest.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,16 @@ public function testBind()
5151
];
5252
$expectedResult = [
5353
'dimensions' => ['scope' => ['value' => 'default']],
54-
'queries' => ['query' => ['value' => 'match_query']],
55-
'filters' => ['filter' => ['from' => 'filter_from', 'to' => 'filter_to', 'value' => 'filter_value']],
56-
'aggregations' => ['price' => ['method' => 'filter_method']],
54+
'queries' => ['query' => ['value' => 'match_query', 'is_bind' => true]],
55+
'filters' => [
56+
'filter' => [
57+
'from' => 'filter_from',
58+
'to' => 'filter_to',
59+
'value' => 'filter_value',
60+
'is_bind' => true
61+
]
62+
],
63+
'aggregations' => ['price' => ['method' => 'filter_method', 'is_bind' => true]],
5764
'from' => 1,
5865
'size' => 10,
5966
];

0 commit comments

Comments
 (0)