Skip to content

Commit

Permalink
Merge pull request #3792 from magento-arcticfoxes/2.3.1-qwerty-pr
Browse files Browse the repository at this point in the history
[2.3.1-qwerty] Sync with 2.3.1-release
  • Loading branch information
joanhe authored Feb 22, 2019
2 parents 4efed2d + 298a243 commit 5ea8151
Show file tree
Hide file tree
Showing 21 changed files with 87 additions and 408 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private function getProductIdsByActions(array $actions)
$productIds = [];

foreach ($actions as $action) {
if (isset($action['product_id']) && is_int($action['product_id'])) {
if (isset($action['product_id'])) {
$productIds[] = $action['product_id'];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,15 @@ protected function setUp()

public function testFilterProductActions()
{
$typeId = 'recently_compared_product';
$productsData = [
1 => [
'added_at' => 12,
'product_id' => 1,
],
2 => [
'added_at' => 13,
'product_id' => 2,
'product_id' => '2',
],
3 => [
'added_at' => 14,
Expand Down Expand Up @@ -126,10 +127,12 @@ public function testFilterProductActions()
$collection->expects($this->once())
->method('addFilterByUserIdentities')
->with(1, 34);
$collection->expects($this->any())
$collection->expects($this->at(1))
->method('addFieldToFilter')
->withConsecutive(['type_id'], ['product_id']);

->with('type_id', $typeId);
$collection->expects($this->at(2))
->method('addFieldToFilter')
->with('product_id', [1, 2]);
$iterator = new \IteratorIterator(new \ArrayIterator([$frontendAction]));
$collection->expects($this->once())
->method('getIterator')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function getFields(array $context = []): array
foreach ($groups as $group) {
$groupPriceKey = $this->fieldNameResolver->getFieldName(
$priceAttribute,
array_merge($context, ['customerGroupId' => $group->getId()])
['customerGroupId' => $group->getId(), 'websiteId' => $context['websiteId']]
);
$allAttributes[$groupPriceKey] = [
'type' => $this->fieldTypeConverter->convert(FieldTypeConverterInterface::INTERNAL_DATA_TYPE_FLOAT),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ public function build(
array $queryResult,
DataProviderInterface $dataProvider
) {
$buckets = $queryResult['aggregations'][$bucket->getName()]['buckets'] ?? [];
$values = [];
foreach ($buckets as $resultBucket) {
foreach ($queryResult['aggregations'][$bucket->getName()]['buckets'] as $resultBucket) {
$values[$resultBucket['key']] = [
'value' => $resultBucket['key'],
'count' => $resultBucket['doc_count'],
];
}

return $values;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/
namespace Magento\Elasticsearch\SearchAdapter\Query\Builder;

use Magento\Elasticsearch\SearchAdapter\Query\ValueTransformerPool;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Search\Request\Query\BoolExpression;
use Magento\Framework\Search\Request\QueryInterface as RequestQueryInterface;
use Magento\Elasticsearch\Model\Adapter\FieldMapperInterface;
Expand All @@ -28,31 +26,20 @@ class Match implements QueryInterface
private $fieldMapper;

/**
* @deprecated
* @see \Magento\Elasticsearch\SearchAdapter\Query\ValueTransformer\TextTransformer
* @var PreprocessorInterface[]
*/
protected $preprocessorContainer;

/**
* @var ValueTransformerPool
*/
private $valueTransformerPool;

/**
* @param FieldMapperInterface $fieldMapper
* @param PreprocessorInterface[] $preprocessorContainer
* @param ValueTransformerPool|null $valueTransformerPool
*/
public function __construct(
FieldMapperInterface $fieldMapper,
array $preprocessorContainer,
ValueTransformerPool $valueTransformerPool = null
array $preprocessorContainer
) {
$this->fieldMapper = $fieldMapper;
$this->preprocessorContainer = $preprocessorContainer;
$this->valueTransformerPool = $valueTransformerPool ?? ObjectManager::getInstance()
->get(ValueTransformerPool::class);
}

/**
Expand Down Expand Up @@ -85,6 +72,10 @@ public function build(array $selectQuery, RequestQueryInterface $requestQuery, $
*/
protected function prepareQuery($queryValue, $conditionType)
{
$queryValue = $this->escape($queryValue);
foreach ($this->preprocessorContainer as $preprocessor) {
$queryValue = $preprocessor->process($queryValue);
}
$condition = $conditionType === BoolExpression::QUERY_CONDITION_NOT ?
self::QUERY_CONDITION_MUST_NOT : $conditionType;
return [
Expand Down Expand Up @@ -113,34 +104,21 @@ protected function buildQueries(array $matches, array $queryValue)

// Checking for quoted phrase \"phrase test\", trim escaped surrounding quotes if found
$count = 0;
$value = preg_replace('#^"(.*)"$#m', '$1', $queryValue['value'], -1, $count);
$value = preg_replace('#^\\\\"(.*)\\\\"$#m', '$1', $queryValue['value'], -1, $count);
$condition = ($count) ? 'match_phrase' : 'match';

$attributesTypes = $this->fieldMapper->getAllAttributesTypes();
$transformedTypes = [];
foreach ($matches as $match) {
$resolvedField = $this->fieldMapper->getFieldName(
$match['field'],
['type' => FieldMapperInterface::TYPE_QUERY]
);
$valueTransformer = $this->valueTransformerPool->get($attributesTypes[$resolvedField]['type'] ?? 'text');
$valueTransformerHash = \spl_object_hash($valueTransformer);
if (!isset($transformedTypes[$valueTransformerHash])) {
$transformedTypes[$valueTransformerHash] = $valueTransformer->transform($value);
}
$transformedValue = $transformedTypes[$valueTransformerHash];
if (null === $transformedValue) {
//Value is incompatible with this field type.
continue;
}

$conditions[] = [
'condition' => $queryValue['condition'],
'body' => [
$condition => [
$resolvedField => [
'query' => $transformedValue,
'boost' => $match['boost'] ?? 1,
'query' => $value,
'boost' => isset($match['boost']) ? $match['boost'] : 1,
],
],
],
Expand All @@ -153,13 +131,16 @@ protected function buildQueries(array $matches, array $queryValue)
/**
* Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.
*
* @deprecated
* @see \Magento\Elasticsearch\SearchAdapter\Query\ValueTransformer\TextTransformer
* Cut trailing plus or minus sign, and @ symbol, using of which causes InnoDB to report a syntax error.
* https://dev.mysql.com/doc/refman/5.7/en/fulltext-boolean.html Fulltext-boolean search docs.
*
* @param string $value
* @return string
*/
protected function escape($value)
{
$value = preg_replace('/@+|[@+-]+$/', '', $value);

$pattern = '/(\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\\\)/';
$replace = '\\\$1';

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 5ea8151

Please sign in to comment.