diff --git a/src/module-elasticsuite-catalog-optimizer/Model/Optimizer/Applier/AttributeValue.php b/src/module-elasticsuite-catalog-optimizer/Model/Optimizer/Applier/AttributeValue.php index a32a4e1b1..af3f93d96 100644 --- a/src/module-elasticsuite-catalog-optimizer/Model/Optimizer/Applier/AttributeValue.php +++ b/src/module-elasticsuite-catalog-optimizer/Model/Optimizer/Applier/AttributeValue.php @@ -57,7 +57,10 @@ public function getFunction(ContainerConfigurationInterface $containerConfigurat { $field = $this->getField($containerConfiguration, $optimizer); $scaleFactor = (float) $optimizer->getConfig('scale_factor'); - + $queryName = sprintf('Optimizer [%s]:%d', $optimizer->getName(), $optimizer->getId()); + $query = $optimizer->getRuleCondition()->getSearchQuery(); + $query->setName(($query->getName() !== '') ? $queryName . " => " . $query->getName() : $queryName); + $function = [ 'field_value_factor' => [ 'field' => $field, @@ -65,7 +68,7 @@ public function getFunction(ContainerConfigurationInterface $containerConfigurat 'modifier' => $optimizer->getConfig('scale_function'), 'missing' => 1 / $scaleFactor, ], - 'filter' => $optimizer->getRuleCondition()->getSearchQuery(), + 'filter' => $query, ]; return $function; diff --git a/src/module-elasticsuite-catalog-optimizer/Model/Optimizer/Applier/ConstantScore.php b/src/module-elasticsuite-catalog-optimizer/Model/Optimizer/Applier/ConstantScore.php index 552640aeb..6daf98693 100644 --- a/src/module-elasticsuite-catalog-optimizer/Model/Optimizer/Applier/ConstantScore.php +++ b/src/module-elasticsuite-catalog-optimizer/Model/Optimizer/Applier/ConstantScore.php @@ -31,9 +31,13 @@ class ConstantScore implements ApplierInterface */ public function getFunction(ContainerConfigurationInterface $containerConfiguration, OptimizerInterface $optimizer) { + $queryName = sprintf('Optimizer [%s]:%d', $optimizer->getName(), $optimizer->getId()); + $query = $optimizer->getRuleCondition()->getSearchQuery(); + $query->setName(($query->getName() !== '') ? $queryName . " => " . $query->getName() : $queryName); + $function = [ 'weight' => 1 + ((float) $optimizer->getConfig('constant_score_value') / 100), - 'filter' => $optimizer->getRuleCondition()->getSearchQuery(), + 'filter' => $query, ]; return $function; 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..1a86049af 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 @@ -99,7 +99,7 @@ public function getSearchQuery(ProductCondition $productCondition) $queryParams = ['field' => $this->getSearchFieldName($productCondition)]; } - $query = $this->prepareQuery($queryType, $queryParams); + $query = $this->prepareQuery($queryType, $queryParams)->setName($productCondition->asString()); if (substr($productCondition->getOperator(), 0, 1) === '!') { $query = $this->applyNegation($query); @@ -122,6 +122,7 @@ public function getSearchQuery(ProductCondition $productCondition) } $query = $this->queryFactory->create(QueryInterface::TYPE_NESTED, $nestedQueryParams); + $query->setName($productCondition->asString()); } } @@ -179,7 +180,11 @@ private function getMatchQueryParams(ProductCondition $productCondition) $queryText = $productCondition->getValue(); $minimumShouldMatch = "100%"; - return ['field' => $fieldName, 'queryText' => $queryText, 'minimumShouldMatch' => $minimumShouldMatch]; + return [ + 'field' => $fieldName, + 'queryText' => $queryText, + 'minimumShouldMatch' => $minimumShouldMatch + ]; } /** 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/Range.php b/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Request/Query/Builder/Range.php index 455a7732c..54b62f604 100644 --- a/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Request/Query/Builder/Range.php +++ b/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Request/Query/Builder/Range.php @@ -41,7 +41,7 @@ public function buildQuery(QueryInterface $query) $searchQuery = ['range' => [$query->getField() => $queryParams]]; if ($query->getName()) { - $searchQuery['range']['_name'] = $query->getName(); + // Intentional omission of the '_name' management because range query does not support it. } 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..3ac5b7bd4 100644 --- a/src/module-elasticsuite-core/Search/Request/Query/Fulltext/QueryBuilder.php +++ b/src/module-elasticsuite-core/Search/Request/Query/Fulltext/QueryBuilder.php @@ -81,22 +81,22 @@ public function create(ContainerConfigurationInterface $containerConfig, $queryT } $query = $this->queryFactory->create(QueryInterface::TYPE_BOOL, ['should' => $queries, 'boost' => $boost]); } elseif ($spellingType == SpellcheckerInterface::SPELLING_TYPE_PURE_STOPWORDS) { - $query = $this->getPureStopwordsQuery($containerConfig, $queryText, $boost); + $query = $this->getPureStopwordsQuery($containerConfig, $queryText, $boost)->setName('PURE_STOPWORDS'); } elseif (in_array($spellingType, $fuzzySpellingTypes)) { - $query = $this->getSpellcheckedQuery($containerConfig, $queryText, $spellingType, $boost); + $query = $this->getSpellcheckedQuery($containerConfig, $queryText, $spellingType, $boost)->setName('SPELLCHECK'); } if ($query === null) { $queryParams = [ - 'query' => $this->getWeightedSearchQuery($containerConfig, $queryText), - 'filter' => $this->getCutoffFrequencyQuery($containerConfig, $queryText), + 'query' => $this->getWeightedSearchQuery($containerConfig, $queryText)->setName('EXACT'), + 'filter' => $this->getCutoffFrequencyQuery($containerConfig, $queryText)->setName('CUTOFF_FREQUENCY'), 'boost' => $boost, ]; $query = $this->queryFactory->create(QueryInterface::TYPE_FILTER, $queryParams); $relevanceConfig = $containerConfig->getRelevanceConfig(); if ($relevanceConfig->getSpanMatchBoost()) { - $spanQuery = $this->getSpanQuery($containerConfig, $queryText, $relevanceConfig->getSpanMatchBoost()); + $spanQuery = $this->getSpanQuery($containerConfig, $queryText, $relevanceConfig->getSpanMatchBoost())->setName('SPAN'); if ($spanQuery !== null) { $queryParams = [ 'must' => [$query], @@ -246,11 +246,11 @@ private function getSpellcheckedQuery(ContainerConfigurationInterface $container $queryClauses = []; if ($relevanceConfig->isFuzzinessEnabled()) { - $queryClauses[] = $this->getFuzzyQuery($containerConfig, $queryText); + $queryClauses[] = $this->getFuzzyQuery($containerConfig, $queryText)->setName('FUZZY'); } if ($relevanceConfig->isPhoneticSearchEnabled()) { - $queryClauses[] = $this->getPhoneticQuery($containerConfig, $queryText); + $queryClauses[] = $this->getPhoneticQuery($containerConfig, $queryText)->setName('PHONETIC'); } if (!empty($queryClauses)) { diff --git a/src/module-elasticsuite-virtual-category/Model/Rule.php b/src/module-elasticsuite-virtual-category/Model/Rule.php index 85b5b48b6..f515f243c 100644 --- a/src/module-elasticsuite-virtual-category/Model/Rule.php +++ b/src/module-elasticsuite-virtual-category/Model/Rule.php @@ -430,7 +430,8 @@ private function getVirtualCategoryQuery( $query = $category->getVirtualRule()->getConditions()->getSearchQuery($excludedCategories); if ($query instanceof QueryInterface) { - $query->setName(sprintf('(%s) virtual category [%s]:%d', $category->getPath(), $category->getName(), $category->getId())); + $queryName = sprintf('(%s) virtual category [%s]:%d', $category->getPath(), $category->getName(), $category->getId()); + $query->setName(($query->getName() !== '') ? $queryName . " => " . $query->getName() : $queryName); } if ($rootCategory && $rootCategory->getId()) { $rootQuery = $this->getCategorySearchQuery($rootCategory, $excludedCategories); 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..ed65cf899 100644 --- a/src/module-elasticsuite-virtual-category/Model/Rule/Condition/Combine.php +++ b/src/module-elasticsuite-virtual-category/Model/Rule/Condition/Combine.php @@ -57,6 +57,7 @@ public function getSearchQuery($excludedCategories = []): QueryInterface } $query = $this->queryFactory->create(QueryInterface::TYPE_BOOL, $queryParams); + $query->setName($this->asStringRecursive()); return $query; }