diff --git a/vendor/magento/module-catalog-graph-ql/etc/search_request.xml b/vendor/magento/module-catalog-graph-ql/etc/search_request.xml index ab1eea9eb6fd..5a452a1540cd 100644 --- a/vendor/magento/module-catalog-graph-ql/etc/search_request.xml +++ b/vendor/magento/module-catalog-graph-ql/etc/search_request.xml @@ -15,6 +15,7 @@ + @@ -23,6 +24,11 @@ + + + + + @@ -61,6 +67,7 @@ + @@ -69,6 +76,11 @@ + + + + + diff --git a/vendor/magento/module-catalog-search/etc/search_request.xml b/vendor/magento/module-catalog-search/etc/search_request.xml index 6f9eb6e20666..2111c469986e 100644 --- a/vendor/magento/module-catalog-search/etc/search_request.xml +++ b/vendor/magento/module-catalog-search/etc/search_request.xml @@ -14,6 +14,7 @@ + @@ -21,6 +22,11 @@ + + + + + diff --git a/vendor/magento/module-elasticsearch/Model/Adapter/FieldsMappingPreprocessorInterface.php b/vendor/magento/module-elasticsearch/Model/Adapter/FieldsMappingPreprocessorInterface.php new file mode 100644 index 000000000000..6eea6560f727 --- /dev/null +++ b/vendor/magento/module-elasticsearch/Model/Adapter/FieldsMappingPreprocessorInterface.php @@ -0,0 +1,22 @@ +validateValue(); + return $result; + } + + /** + * Validates config value + * + * @throws LocalizedException + */ + public function validateValue(): void + { + if (strlen($this->getValue()) && !preg_match('/^((\d+<)?-?\d+%?\s?)+$/', $this->getValue())) { + throw new LocalizedException( + __( + 'Value for the field "%1" was not saved because of the incorrect format.', + __('Minimum Terms to Match') + ) + ); + } + } +} diff --git a/vendor/magento/module-elasticsearch/SearchAdapter/Query/Builder/Match.php b/vendor/magento/module-elasticsearch/SearchAdapter/Query/Builder/Match.php index f96672f616f2..690d0f74435d 100644 --- a/vendor/magento/module-elasticsearch/SearchAdapter/Query/Builder/Match.php +++ b/vendor/magento/module-elasticsearch/SearchAdapter/Query/Builder/Match.php @@ -7,6 +7,7 @@ use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeProvider; use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\ResolverInterface as TypeResolver; +use Magento\Elasticsearch\Model\Config; use Magento\Elasticsearch\SearchAdapter\Query\ValueTransformerPool; use Magento\Framework\App\ObjectManager; use Magento\Framework\Search\Request\Query\BoolExpression; @@ -50,6 +51,10 @@ class Match implements QueryInterface * @var ValueTransformerPool */ private $valueTransformerPool; + /** + * @var Config + */ + private $config; /** * @param FieldMapperInterface $fieldMapper @@ -57,13 +62,15 @@ class Match implements QueryInterface * @param AttributeProvider|null $attributeProvider * @param TypeResolver|null $fieldTypeResolver * @param ValueTransformerPool|null $valueTransformerPool + * @param Config|null $config */ public function __construct( FieldMapperInterface $fieldMapper, array $preprocessorContainer, AttributeProvider $attributeProvider = null, TypeResolver $fieldTypeResolver = null, - ValueTransformerPool $valueTransformerPool = null + ValueTransformerPool $valueTransformerPool = null, + Config $config = null ) { $this->fieldMapper = $fieldMapper; $this->preprocessorContainer = $preprocessorContainer; @@ -73,6 +80,7 @@ public function __construct( ->get(TypeResolver::class); $this->valueTransformerPool = $valueTransformerPool ?? ObjectManager::getInstance() ->get(ValueTransformerPool::class); + $this->config = $config ?? ObjectManager::getInstance()->get(Config::class); } /** @@ -83,11 +91,15 @@ public function build(array $selectQuery, RequestQueryInterface $requestQuery, $ $queryValue = $this->prepareQuery($requestQuery->getValue(), $conditionType); $queries = $this->buildQueries($requestQuery->getMatches(), $queryValue); $requestQueryBoost = $requestQuery->getBoost() ?: 1; + $minimumShouldMatch = $this->config->getElasticsearchConfigData('minimum_should_match'); foreach ($queries as $query) { $queryBody = $query['body']; - $matchKey = isset($queryBody['match_phrase']) ? 'match_phrase' : 'match'; + $matchKey = array_keys($queryBody)[0]; foreach ($queryBody[$matchKey] as $field => $matchQuery) { $matchQuery['boost'] = $requestQueryBoost + $matchQuery['boost']; + if ($minimumShouldMatch && $matchKey != 'match_phrase_prefix') { + $matchQuery['minimum_should_match'] = $minimumShouldMatch; + } $queryBody[$matchKey][$field] = $matchQuery; } $selectQuery['bool'][$query['condition']][] = $queryBody; @@ -156,10 +168,11 @@ protected function buildQueries(array $matches, array $queryValue) continue; } + $matchCondition = $match['matchCondition'] ?? $condition; $conditions[] = [ 'condition' => $queryValue['condition'], 'body' => [ - $condition => [ + $matchCondition => [ $resolvedField => [ 'query' => $transformedValue, 'boost' => $match['boost'] ?? 1, diff --git a/vendor/magento/module-elasticsearch/etc/adminhtml/system.xml b/vendor/magento/module-elasticsearch/etc/adminhtml/system.xml index dd42b408ff75..1f61a48db9bf 100644 --- a/vendor/magento/module-elasticsearch/etc/adminhtml/system.xml +++ b/vendor/magento/module-elasticsearch/etc/adminhtml/system.xml @@ -55,7 +55,15 @@ elasticsearch - + + + + elasticsearch + + here for possible values.]]> + Magento\Elasticsearch\Model\Config\Backend\MinimumShouldMatch + + - + + + + elasticsearch5 + + here for possible values.]]> + Magento\Elasticsearch\Model\Config\Backend\MinimumShouldMatch + + - + + + elasticsearch6 + + here for possible values.]]> + Magento\Elasticsearch\Model\Config\Backend\MinimumShouldMatch + + +