diff --git a/src/module-elasticsuite-catalog-rule/Model/Rule/Condition/Combine.php b/src/module-elasticsuite-catalog-rule/Model/Rule/Condition/Combine.php index 6ebd86a52..05ad5bc79 100644 --- a/src/module-elasticsuite-catalog-rule/Model/Rule/Condition/Combine.php +++ b/src/module-elasticsuite-catalog-rule/Model/Rule/Condition/Combine.php @@ -162,6 +162,7 @@ public function getSearchQuery() } } + $queryParams['name'] = $this->asStringRecursive(); $query = $this->queryFactory->create(QueryInterface::TYPE_BOOL, $queryParams); return $query; diff --git a/src/module-elasticsuite-catalog-rule/Model/Rule/Condition/Product/QueryBuilder.php b/src/module-elasticsuite-catalog-rule/Model/Rule/Condition/Product/QueryBuilder.php index ed217c99c..391c4f929 100644 --- a/src/module-elasticsuite-catalog-rule/Model/Rule/Condition/Product/QueryBuilder.php +++ b/src/module-elasticsuite-catalog-rule/Model/Rule/Condition/Product/QueryBuilder.php @@ -87,6 +87,7 @@ public function getSearchQuery(ProductCondition $productCondition) $this->prepareFieldValue($productCondition); $queryType = QueryInterface::TYPE_TERMS; $queryParams = $this->getTermsQueryParams($productCondition); + $queryParams['name'] = $productCondition->asString(); if ($productCondition->getInputType() === 'string' && !in_array($productCondition->getOperator(), ['()', '!()', '<=>'])) { $queryType = QueryInterface::TYPE_MATCH; @@ -121,6 +122,7 @@ public function getSearchQuery(ProductCondition $productCondition) $nestedQueryParams['query'] = $nestedFilter; } + $nestedQueryParams['name'] = $productCondition->asString(); $query = $this->queryFactory->create(QueryInterface::TYPE_NESTED, $nestedQueryParams); } } @@ -179,7 +181,12 @@ private function getMatchQueryParams(ProductCondition $productCondition) $queryText = $productCondition->getValue(); $minimumShouldMatch = "100%"; - return ['field' => $fieldName, 'queryText' => $queryText, 'minimumShouldMatch' => $minimumShouldMatch]; + return [ + 'field' => $fieldName, + 'queryText' => $queryText, + 'minimumShouldMatch' => $minimumShouldMatch, + 'name' => $productCondition->asString(), + ]; } /** diff --git a/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Request/Query/Builder/MatchQuery.php b/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Request/Query/Builder/MatchQuery.php index d7b512c1f..e7fc91407 100644 --- a/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Request/Query/Builder/MatchQuery.php +++ b/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Request/Query/Builder/MatchQuery.php @@ -41,12 +41,12 @@ public function buildQuery(QueryInterface $query) 'boost' => $query->getBoost(), ]; - $searchQuery = ['match' => [$query->getField() => $searchQueryParams]]; - if ($query->getName()) { - $searchQuery['match']['_name'] = $query->getName(); + $searchQueryParams['_name'] = $query->getName(); } + $searchQuery = ['match' => [$query->getField() => $searchQueryParams]]; + return $searchQuery; } } diff --git a/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Request/Query/Builder/Span/SpanFirst.php b/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Request/Query/Builder/Span/SpanFirst.php index 7aab83f8b..df7124c68 100644 --- a/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Request/Query/Builder/Span/SpanFirst.php +++ b/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Request/Query/Builder/Span/SpanFirst.php @@ -37,12 +37,18 @@ public function buildQuery(QueryInterface $query) throw new \InvalidArgumentException("Query builder : invalid query type {$query->getType()}"); } - return [ + $searchQuery = [ 'span_first' => [ 'boost' => $query->getBoost(), 'match' => $this->parentBuilder->buildQuery($query->getMatch()), 'end' => $query->getEnd(), ], ]; + + if ($query->getName()) { + $searchQuery['span_first']['_name'] = $query->getName(); + } + + return $searchQuery; } } diff --git a/src/module-elasticsuite-core/Search/Request/Query/Fulltext/QueryBuilder.php b/src/module-elasticsuite-core/Search/Request/Query/Fulltext/QueryBuilder.php index 95d71e14c..a8e4c6307 100644 --- a/src/module-elasticsuite-core/Search/Request/Query/Fulltext/QueryBuilder.php +++ b/src/module-elasticsuite-core/Search/Request/Query/Fulltext/QueryBuilder.php @@ -91,6 +91,7 @@ public function create(ContainerConfigurationInterface $containerConfig, $queryT 'query' => $this->getWeightedSearchQuery($containerConfig, $queryText), 'filter' => $this->getCutoffFrequencyQuery($containerConfig, $queryText), 'boost' => $boost, + 'name' => 'EXACT', ]; $query = $this->queryFactory->create(QueryInterface::TYPE_FILTER, $queryParams); @@ -223,6 +224,7 @@ private function getPureStopwordsQuery(ContainerConfigurationInterface $containe 'minimumShouldMatch' => "100%", 'tieBreaker' => $relevanceConfig->getTieBreaker(), 'boost' => $boost, + 'name' => 'PURE_STOPWORDS', ]; return $this->queryFactory->create(QueryInterface::TYPE_MULTIMATCH, $queryParams); @@ -254,7 +256,7 @@ private function getSpellcheckedQuery(ContainerConfigurationInterface $container } if (!empty($queryClauses)) { - $queryParams = ['should' => $queryClauses, 'boost' => $boost]; + $queryParams = ['should' => $queryClauses, 'boost' => $boost, 'name' => 'FUZZY']; if ($spellingType == SpellcheckerInterface::SPELLING_TYPE_MOST_FUZZY) { $queryParams['must'] = [$this->getWeightedSearchQuery($containerConfig, $queryText)]; @@ -306,6 +308,7 @@ private function getFuzzyQuery(ContainerConfigurationInterface $containerConfig, 'tieBreaker' => $relevanceConfig->getTieBreaker(), 'fuzzinessConfig' => $relevanceConfig->getFuzzinessConfiguration(), 'cutoffFrequency' => $relevanceConfig->getCutoffFrequency(), + 'name' => 'FUZZY', ]; return $this->queryFactory->create(QueryInterface::TYPE_MULTIMATCH, $queryParams); @@ -338,6 +341,7 @@ private function getPhoneticQuery(ContainerConfigurationInterface $containerConf 'minimumShouldMatch' => $minimumShouldMatch, 'tieBreaker' => $relevanceConfig->getTieBreaker(), 'cutoffFrequency' => $relevanceConfig->getCutoffFrequency(), + 'name' => 'PHONETIC', ]; return $this->queryFactory->create(QueryInterface::TYPE_MULTIMATCH, $queryParams); @@ -394,7 +398,7 @@ private function getSpanQuery(ContainerConfigurationInterface $containerConfig, $spanFieldsFilter = $this->fieldFilters['spannableFieldFilter']; $spanFields = $containerConfig->getMapping()->getFields(); $spanFields = array_filter($spanFields, [$spanFieldsFilter, 'filterField']); - $spanQueryParams = ['boost' => $boost, 'end' => $wordCount]; + $spanQueryParams = ['boost' => $boost, 'end' => $wordCount, 'name' => 'SPAN']; $spanQueryType = SpanQueryInterface::TYPE_SPAN_FIRST; if (count($spanFields) > 0) { diff --git a/src/module-elasticsuite-virtual-category/Model/Rule/Condition/Combine.php b/src/module-elasticsuite-virtual-category/Model/Rule/Condition/Combine.php index 19d0cbb58..8435486c8 100644 --- a/src/module-elasticsuite-virtual-category/Model/Rule/Condition/Combine.php +++ b/src/module-elasticsuite-virtual-category/Model/Rule/Condition/Combine.php @@ -56,6 +56,7 @@ public function getSearchQuery($excludedCategories = []): QueryInterface } } + $queryParams['name'] = $this->asStringRecursive(); $query = $this->queryFactory->create(QueryInterface::TYPE_BOOL, $queryParams); return $query;