diff --git a/src/module-elasticsuite-core/Api/Search/Request/Container/RelevanceConfigurationInterface.php b/src/module-elasticsuite-core/Api/Search/Request/Container/RelevanceConfigurationInterface.php index 0c295ab77..00c7df697 100644 --- a/src/module-elasticsuite-core/Api/Search/Request/Container/RelevanceConfigurationInterface.php +++ b/src/module-elasticsuite-core/Api/Search/Request/Container/RelevanceConfigurationInterface.php @@ -108,4 +108,11 @@ public function isUsingAllTokens(); * @return bool */ public function isUsingReferenceAnalyzer(); + + /** + * If we should use the default analyzer of each field when building the exact match filter query. + * + * @return bool + */ + public function isUsingDefaultAnalyzerInExactMatchFilter(); } diff --git a/src/module-elasticsuite-core/Search/Request/ContainerConfiguration/RelevanceConfig.php b/src/module-elasticsuite-core/Search/Request/ContainerConfiguration/RelevanceConfig.php index b4ea04436..52d326167 100644 --- a/src/module-elasticsuite-core/Search/Request/ContainerConfiguration/RelevanceConfig.php +++ b/src/module-elasticsuite-core/Search/Request/ContainerConfiguration/RelevanceConfig.php @@ -75,6 +75,11 @@ class RelevanceConfig implements RelevanceConfigurationInterface */ private $useReferenceInExactMatchFilter; + /** + * @var bool + */ + private $useDefaultAnalyzerInExactMatchFilter; + /** * @var boolean */ @@ -91,22 +96,24 @@ class RelevanceConfig implements RelevanceConfigurationInterface * @SuppressWarnings(PHPMD.BooleanArgumentFlag) * @SuppressWarnings(PHPMD.ExcessiveParameterList) * - * @param string $minimumShouldMatch Minimum should match clause of the text query. - * @param float $tieBreaker Tie breaker for multimatch queries. - * @param int|null $phraseMatchBoost The Phrase match boost value, or null if not - * enabled - * @param float $cutOffFrequency The cutoff Frequency value - * @param FuzzinessConfigurationInterface|null $fuzziness The fuzziness Configuration, or null - * @param boolean $enablePhoneticSearch The phonetic Configuration, or null - * @param int|null $spanMatchBoost The Span match boost value, or null if not - * enabled - * @param int|null $spanSize The number of terms to match in span queries - * @param int|null $minScore The Min Score value, or null if not enabled - * @param boolean $useReferenceInExactMatchFilter Whether to use the reference collector field instead of - * the 'sku' field in the exact match filter query - * @param boolean $useAllTokens Whether to take into account all term vectors tokens - * @param boolean $useReferenceAnalyzer Whether to include the collector field associated - * with the reference analyzer in term vectors request + * @param string $minimumShouldMatch Minimum should match clause of the text query. + * @param float $tieBreaker Tie breaker for multimatch queries. + * @param int|null $phraseMatchBoost The Phrase match boost value, or null if not + * enabled + * @param float $cutOffFrequency The cutoff Frequency value + * @param FuzzinessConfigurationInterface|null $fuzziness The fuzziness Configuration, or null + * @param boolean $enablePhoneticSearch The phonetic Configuration, or null + * @param int|null $spanMatchBoost The Span match boost value, or null if not + * enabled + * @param int|null $spanSize The number of terms to match in span queries + * @param int|null $minScore The Min Score value, or null if not enabled + * @param boolean $useReferenceInExactMatchFilter Whether to use the reference collector field + * instead of 'sku' field in the exact match filter + * @param boolean $useDefaultAnalyzerInExactMatchFilter Whether to use 'field' or 'field.default_analyzer' + * in the exact match filter query + * @param boolean $useAllTokens Whether to take into account all term vectors tokens + * @param boolean $useReferenceAnalyzer Whether to include the collector field associated + * with the reference analyzer in term vectors request */ public function __construct( $minimumShouldMatch, @@ -119,6 +126,7 @@ public function __construct( $spanSize = null, $minScore = null, $useReferenceInExactMatchFilter = false, + $useDefaultAnalyzerInExactMatchFilter = false, $useAllTokens = false, $useReferenceAnalyzer = false ) { @@ -134,6 +142,7 @@ public function __construct( $this->useReferenceInExactMatchFilter = $useReferenceInExactMatchFilter; $this->useAllTokens = $useAllTokens; $this->useReferenceAnalyzer = $useReferenceAnalyzer; + $this->useDefaultAnalyzerInExactMatchFilter = $useDefaultAnalyzerInExactMatchFilter; } /** @@ -230,6 +239,14 @@ public function isUsingReferenceInExactMatchFilter() return (bool) $this->useReferenceInExactMatchFilter; } + /** + * {@inheritDoc} + */ + public function isUsingDefaultAnalyzerInExactMatchFilter() + { + return (bool) $this->useDefaultAnalyzerInExactMatchFilter; + } + /** * {@inheritDoc} */ diff --git a/src/module-elasticsuite-core/Search/Request/ContainerConfiguration/RelevanceConfig/Factory.php b/src/module-elasticsuite-core/Search/Request/ContainerConfiguration/RelevanceConfig/Factory.php index b884e4e2a..0ca838b2a 100644 --- a/src/module-elasticsuite-core/Search/Request/ContainerConfiguration/RelevanceConfig/Factory.php +++ b/src/module-elasticsuite-core/Search/Request/ContainerConfiguration/RelevanceConfig/Factory.php @@ -73,6 +73,11 @@ class Factory */ const MIN_SCORE_CONFIG_XML_PREFIX = 'min_score_configuration'; + /** + * XML node for exact match configuration + */ + const EXACT_MATCH_CONFIG_XML_PREFIX = 'exact_match_configuration'; + /** * XML node for using reference in the exact match filter query */ @@ -165,6 +170,7 @@ protected function loadConfiguration($scopeCode) 'useReferenceInExactMatchFilter' => $this->isUsingReferenceInExactMatchFilter($scopeCode), 'useAllTokens' => $this->isUsingAllTokensConfiguration($scopeCode), 'useReferenceAnalyzer' => $this->isUsingReferenceAnalyzerConfiguration($scopeCode), + 'useDefaultAnalyzerInExactMatchFilter' => $this->isUsingDefaultAnalyzerInExactMatchFilter($scopeCode), ]; return $configurationParams; @@ -410,4 +416,18 @@ private function isUsingReferenceAnalyzerConfiguration($scopeCode) { return (bool) $this->getConfigValue(self::TERM_VECTORS_USE_REFERENCE_CONFIG_XML_PATH, $scopeCode); } + + /** + * Check if we should use the default analyzer of each field when building the exact match filter query. + * + * @param @param string $scopeCode The scope code + * + * @return bool + */ + private function isUsingDefaultAnalyzerInExactMatchFilter($scopeCode) + { + $path = self::BASE_RELEVANCE_CONFIG_XML_PREFIX . "/" . self::EXACT_MATCH_CONFIG_XML_PREFIX; + + return (bool) $this->getConfigValue($path . "/use_default_analyzer", $scopeCode); + } } 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 ffc79f0ed..53c5cec54 100644 --- a/src/module-elasticsuite-core/Search/Request/Query/Fulltext/QueryBuilder.php +++ b/src/module-elasticsuite-core/Search/Request/Query/Fulltext/QueryBuilder.php @@ -116,16 +116,25 @@ public function create(ContainerConfigurationInterface $containerConfig, $queryT private function getCutoffFrequencyQuery(ContainerConfigurationInterface $containerConfig, $queryText) { $relevanceConfig = $containerConfig->getRelevanceConfig(); + $fields = array_fill_keys([MappingInterface::DEFAULT_SEARCH_FIELD, 'sku'], 1); - $nonStandardSearchableFieldFilter = $this->fieldFilters['nonStandardSearchableFieldFilter']; + if ($containerConfig->getRelevanceConfig()->isUsingDefaultAnalyzerInExactMatchFilter()) { + $nonStandardSearchableFieldFilter = $this->fieldFilters['nonStandardSearchableFieldFilter']; - $defaultFields = array_fill_keys([MappingInterface::DEFAULT_SEARCH_FIELD, 'sku'], 1); - $fields = $defaultFields + $this->getWeightedFields( - $containerConfig, - null, - $nonStandardSearchableFieldFilter, - MappingInterface::DEFAULT_SEARCH_FIELD - ); + $fields = $fields + $this->getWeightedFields( + $containerConfig, + null, + $nonStandardSearchableFieldFilter, + MappingInterface::DEFAULT_SEARCH_FIELD + ); + } + + if ($containerConfig->getRelevanceConfig()->isUsingReferenceInExactMatchFilter()) { + $fields += array_fill_keys( + [MappingInterface::DEFAULT_SEARCH_FIELD, MappingInterface::DEFAULT_REFERENCE_FIELD . ".reference"], + 1 + ); + } $queryParams = [ 'fields' => array_fill_keys(array_keys($fields), 1), @@ -134,13 +143,6 @@ private function getCutoffFrequencyQuery(ContainerConfigurationInterface $contai 'minimumShouldMatch' => $relevanceConfig->getMinimumShouldMatch(), ]; - if ($containerConfig->getRelevanceConfig()->isUsingReferenceInExactMatchFilter()) { - $queryParams['fields'] = array_fill_keys( - [MappingInterface::DEFAULT_SEARCH_FIELD, MappingInterface::DEFAULT_REFERENCE_FIELD . ".reference"], - 1 - ); - } - return $this->queryFactory->create(QueryInterface::TYPE_MULTIMATCH, $queryParams); } diff --git a/src/module-elasticsuite-core/etc/adminhtml/elasticsuite_relevance.xml b/src/module-elasticsuite-core/etc/adminhtml/elasticsuite_relevance.xml index 95a62e5b4..659303e8e 100644 --- a/src/module-elasticsuite-core/etc/adminhtml/elasticsuite_relevance.xml +++ b/src/module-elasticsuite-core/etc/adminhtml/elasticsuite_relevance.xml @@ -99,6 +99,11 @@ + + + Magento\Config\Model\Config\Source\Yesno + + Magento\Config\Model\Config\Source\Yesno diff --git a/src/module-elasticsuite-core/etc/elasticsuite_relevance.xml b/src/module-elasticsuite-core/etc/elasticsuite_relevance.xml index 045e99f50..cf710eaa6 100644 --- a/src/module-elasticsuite-core/etc/elasticsuite_relevance.xml +++ b/src/module-elasticsuite-core/etc/elasticsuite_relevance.xml @@ -39,6 +39,7 @@ 0 + 0 0 diff --git a/src/module-elasticsuite-core/i18n/en_US.csv b/src/module-elasticsuite-core/i18n/en_US.csv index bb9a1edb9..83ae3eeda 100644 --- a/src/module-elasticsuite-core/i18n/en_US.csv +++ b/src/module-elasticsuite-core/i18n/en_US.csv @@ -86,3 +86,5 @@ Autocomplete,Autocomplete "Experimental: Take into account all tokens from the term vectors response, instead of one token per position. Useful for sku/reference matching.","Experimental: Take into account all tokens from the term vectors response, instead of one token per position. Useful for sku/reference matching." "[Experimental] Use reference analyzer in term vectors","[Experimental] Use reference analyzer in term vectors" "Experimental: Include the 'reference' collector field which contains all searchable fields using the 'reference' analyzer when performing the term vectors request. Useful for sku/reference matching.","Experimental: Include the 'reference' collector field which contains all searchable fields using the 'reference' analyzer when performing the term vectors request. Useful for sku/reference matching." +"[Experimental] Use default analyzer in exact matching filter query","[Experimental] Use default analyzer in exact matching filter query" +"Experimental: Use the default analyzer of each field instead of the 'standard' analyzer for exact matching. Eg : for sku, it will try to match on 'sku.reference' field. If a field is using 'standard_edge_ngram' analyzer, it will try to match on 'field.standard_edge_ngram'. Useful for partial matching, or matching on beginning of words.","Experimental: Use the default analyzer of each field instead of the 'standard' analyzer for exact matching. Eg : for sku, it will try to match on 'sku.reference' field. If a field is using 'standard_edge_ngram' analyzer, it will try to match on 'field.standard_edge_ngram'. Useful for partial matching, or matching on beginning of words." diff --git a/src/module-elasticsuite-core/i18n/fr_FR.csv b/src/module-elasticsuite-core/i18n/fr_FR.csv index c33c8ef0a..7a6dd26e3 100644 --- a/src/module-elasticsuite-core/i18n/fr_FR.csv +++ b/src/module-elasticsuite-core/i18n/fr_FR.csv @@ -86,3 +86,5 @@ General,Général "Experimental: Take into account all tokens from the term vectors response, instead of one token per position. Useful for sku/reference matching.","Expérimental: Prendre en considération tous les tokens de la réponse des term vectors, plutôt qu'un seul token par position. Utile pour matcher les sku/références." "[Experimental] Use reference analyzer in term vectors","[Expérimental] Utiliser l'analyseur reference dans les term vectors" "Experimental: Include the 'reference' collector field which contains all searchable fields using the 'reference' analyzer when performing the term vectors request. Useful for sku/reference matching.","Expérimental: Inclure le champ collecteur 'reference' qui contient tous les champs cherchables utilisant l'analyseur 'reference' lors de la requête des term vectors. Utile pour le matching de sku/références produit." +"[Experimental] Use default analyzer in exact matching filter query","[Expérimental] Utiliser l'analyseur par défaut des champs dans la recherche exacte" +"Experimental: Use the default analyzer of each field instead of the 'standard' analyzer for exact matching. Eg : for sku, it will try to match on 'sku.reference' field. If a field is using 'standard_edge_ngram' analyzer, it will try to match on 'field.standard_edge_ngram'. Useful for partial matching, or matching on beginning of words.","Expérimental: Utiliser l'analyseur par défaut de chaque champ au lieu de l'analyseur 'standard' pour la recherch exacte. Ex : pour le sku, le moteur essayera de trouver une correspondance exacte sur sku.reference. Si un champ a pour analyseur 'standard_edge_ngram', le moteur tentera de trouver une correspondance exacte sur 'champ.standard_edge_ngram'. Utile pour le matching partiel, ou le matching sur les débuts de mots."