Skip to content

Commit

Permalink
Merge branch '2.10.x' into 2.11.x
Browse files Browse the repository at this point in the history
  • Loading branch information
rbayet committed Oct 28, 2024
2 parents c0dc0ef + a00cadd commit ae1c68b
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/module-elasticsuite-core/i18n/de_DE.csv
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
"Basic HTTP authentication password","Basic HTTP Authentifikation Passwort"
"Enable Debug Mode","Debug Modus aktivieren"
"When enabled the module will produce logs through Magento logging system.","Wenn aktiviert werden vom Modul Logs mit dem Magento Logging System geschrieben."
"Enable logging of request that produce errors","Enable logging of request that produce errors"
"This is an alternative to the debug mode for production environments. If enabled, even when the debug mode is disabled, the body of search requests that produce an error will be logged. If disabled, only the error message/exception message will be logged (legacy behavior). A log rotation system on the var/log/system.log file is advised if enabled.","This is an alternative to the debug mode for production environments. If enabled, even when the debug mode is disabled, the body of search requests that produce an error will be logged. If disabled, only the error message/exception message will be logged (legacy behavior). A log rotation system on the var/log/system.log file is advised if enabled."
"Server Connection Timeout","Server Verbindung Timeout"
"In seconds.","In Sekunden."
"Indices Settings","Einstellungen der Indizes"
Expand Down
2 changes: 2 additions & 0 deletions src/module-elasticsuite-core/i18n/nl_NL.csv
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
"Basic HTTP authentication password","Basis HTTP authenticatie wachtwoord"
"Enable Debug Mode","Debug modus inschakelen"
"When enabled the module will produce logs through Magento logging system.","Indien ingeschakeld zal de module logboeken produceren via Magento logging systeem."
"Enable logging of request that produce errors","Enable logging of request that produce errors"
"This is an alternative to the debug mode for production environments. If enabled, even when the debug mode is disabled, the body of search requests that produce an error will be logged. If disabled, only the error message/exception message will be logged (legacy behavior). A log rotation system on the var/log/system.log file is advised if enabled.","This is an alternative to the debug mode for production environments. If enabled, even when the debug mode is disabled, the body of search requests that produce an error will be logged. If disabled, only the error message/exception message will be logged (legacy behavior). A log rotation system on the var/log/system.log file is advised if enabled."
"Server Connection Timeout","Time-out verbinding server"
"In seconds.","In seconden."
"Indices Settings","Indices instellingen"
Expand Down
10 changes: 10 additions & 0 deletions src/module-elasticsuite-thesaurus/Config/ThesaurusConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ public function getMaxRewrites()
return (int) $this->general['max_rewrites'];
}

/**
* Max allowed alternative queries generated by the synonym engine.
*
* @return int
*/
public function getMaxRewrittenQueries()
{
return (int) $this->general['max_rewritten_queries'];
}

/**
* Is the synonyms search enabled ?
*
Expand Down
40 changes: 36 additions & 4 deletions src/module-elasticsuite-thesaurus/Plugin/QueryRewrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Smile\ElasticsuiteCore\Search\Request\Query\Fulltext\QueryBuilder;
use Smile\ElasticsuiteCore\Api\Search\Request\ContainerConfigurationInterface;
use Smile\ElasticsuiteCore\Search\Request\Query\QueryFactory;
use Smile\ElasticsuiteThesaurus\Config\ThesaurusConfig;
use Smile\ElasticsuiteThesaurus\Config\ThesaurusConfigFactory;
use Smile\ElasticsuiteThesaurus\Model\Index;
use Smile\ElasticsuiteCore\Api\Search\SpellcheckerInterface;
use Smile\ElasticsuiteCore\Search\Request\QueryInterface;
Expand All @@ -35,6 +37,11 @@ class QueryRewrite
*/
private $queryFactory;

/**
* @var ThesaurusConfigFactory
*/
private $thesaurusConfigFactory;

/**
* @var Index
*/
Expand All @@ -48,12 +55,17 @@ class QueryRewrite
/**
* Constructor.
*
* @param QueryFactory $queryFactory Search request query factory.
* @param Index $index Synonym index.
* @param QueryFactory $queryFactory Search request query factory.
* @param ThesaurusConfigFactory $thesaurusConfigFactory Thesaurus configuration factory.
* @param Index $index Synonym index.
*/
public function __construct(QueryFactory $queryFactory, Index $index)
{
public function __construct(
QueryFactory $queryFactory,
ThesaurusConfigFactory $thesaurusConfigFactory,
Index $index
) {
$this->queryFactory = $queryFactory;
$this->thesaurusConfigFactory = $thesaurusConfigFactory;
$this->index = $index;
}

Expand Down Expand Up @@ -141,6 +153,26 @@ private function getWeightedRewrites($queryText, $containerConfig, $originalBoos
$rewrites = $rewrites + $this->index->getQueryRewrites($containerConfig, $currentQueryText, $originalBoost);
}

$maxRewrittenQueries = $this->getThesaurusConfig($containerConfig)->getMaxRewrittenQueries();
if ($maxRewrittenQueries > 0) {
$rewrites = array_slice($rewrites, 0, $maxRewrittenQueries, true);
}

return $rewrites;
}

/**
* Return thesaurus/relevance configuration.
*
* @param ContainerConfigurationInterface $containerConfig Container configuration.
*
* @return ThesaurusConfig
*/
private function getThesaurusConfig(ContainerConfigurationInterface $containerConfig)
{
$storeId = $containerConfig->getStoreId();
$containerName = $containerConfig->getName();

return $this->thesaurusConfigFactory->create($storeId, $containerName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
use Smile\ElasticsuiteCore\Search\Request\Query\Builder;
use Smile\ElasticsuiteCore\Search\Request\Query\QueryFactory;
use Smile\ElasticsuiteCore\Search\Request\QueryInterface;
use Smile\ElasticsuiteThesaurus\Config\ThesaurusConfig;
use Smile\ElasticsuiteThesaurus\Config\ThesaurusConfigFactory;
use Smile\ElasticsuiteThesaurus\Model\Index as ThesaurusIndex;
use Smile\ElasticsuiteThesaurus\Plugin\QueryRewrite;
use Smile\ElasticsuiteThesaurus\Test\Unit\FulltextQueryBuilderInterceptor;
Expand Down Expand Up @@ -89,11 +91,13 @@ public function testMultipleSearchQueryDepthBuilder()
$containerConfig = $this->getContainerConfigMock($this->fields);
$spellingType = SpellcheckerInterface::SPELLING_TYPE_EXACT;

$thesaurusConfigFactory = $this->getThesaurusConfigFactoryMock();

$thesaurusIndex = $this->getMockBuilder(ThesaurusIndex::class)
->disableOriginalConstructor()
->getMock();

$queryRewritePlugin = new QueryRewrite($queryFactory, $thesaurusIndex);
$queryRewritePlugin = new QueryRewrite($queryFactory, $thesaurusConfigFactory, $thesaurusIndex);
$queryBuilderInterceptor = $this->getQueryBuilderWithPlugin($queryFactory, $queryRewritePlugin);

/*
Expand Down Expand Up @@ -130,11 +134,13 @@ public function testMultipleSearchQueryDepthBuilderWithRewrites()
$containerConfig = $this->getContainerConfigMock($this->fields);
$spellingType = SpellcheckerInterface::SPELLING_TYPE_EXACT;

$thesaurusConfigFactory = $this->getThesaurusConfigFactoryMock();

$thesaurusIndex = $this->getMockBuilder(ThesaurusIndex::class)
->disableOriginalConstructor()
->getMock();

$queryRewritePlugin = new QueryRewrite($queryFactory, $thesaurusIndex);
$queryRewritePlugin = new QueryRewrite($queryFactory, $thesaurusConfigFactory, $thesaurusIndex);
$queryBuilderInterceptor = $this->getQueryBuilderWithPlugin($queryFactory, $queryRewritePlugin);

$thesaurusIndex->expects($this->exactly(2))->method('getQueryRewrites')->withConsecutive(
Expand Down Expand Up @@ -219,6 +225,26 @@ private function getQueryFactory($queryTypes)
return new QueryFactory($factories);
}

/**
* Mock the thesaurus config factory.
*
* @return \PHPUnit\Framework\MockObject\MockObject
*/
private function getThesaurusConfigFactoryMock()
{
$thesaurusConfig = $this->getMockBuilder(ThesaurusConfig::class)
->disableOriginalConstructor()
->getMock();
$thesaurusConfig->method('getMaxRewrittenQueries')->will($this->returnValue(0));

$thesaurusConfigFactory = $this->getMockBuilder(ThesaurusConfigFactory::class)
->disableOriginalConstructor()
->getMock();
$thesaurusConfigFactory->method('create')->will($this->returnValue($thesaurusConfig));

return $thesaurusConfigFactory;
}

/**
* Mock the configuration used by the query builder.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@

<group id="general" translate="label" type="text" sortOrder="20" showInDefault="1" showInContainer="1" showInStore="1">
<label>General Configuration</label>
<field id="max_rewrites" translate="label" type="text" sortOrder="10" showInDefault="1" showInContainer="1" showInStore="1">
<field id="max_rewrites" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInContainer="1" showInStore="1">
<label>Max Allowed Rewrites</label>
<comment><![CDATA[Maximum number of thesaurus rules applied at a given time to a given search query to produce alternative queries. That number applies first to the synonyms rules and then the expansion rules. For instance if the setting's value is 2, it means each alternative query will be the result of the application of at most 2 synonyms rules and at most 2 expansion rules. But if you have 10 synonym rules and 5 expansion rules, they could all end up being applied by pairs. So be careful about augmenting this setting's value, especially if you already have a lot of rules with long lists of alternative terms.]]></comment>
</field>
<field id="max_rewritten_queries" translate="label comment" type="text" sortOrder="20" showInDefault="1" showInContainer="1" showInStore="1">
<label>Max Alternative Search Queries</label>
<comment><![CDATA[Maximum number of alternative search queries taken into account. Use this setting if you have performance issues arising on your cluster related to a huge volume of thesaurus rules. Defaults to 0 (no limitation).]]></comment>
<validate>integer validate-number validate-zero-or-greater</validate>
</field>
</group>

Expand All @@ -41,7 +47,7 @@
</depends>
</field>
</group>

<group id="expansions" translate="label" type="text" sortOrder="50" showInDefault="1" showInContainer="1" showInStore="1">
<label>Query Expansions Configuration</label>
<field id="enable" translate="label" type="select" sortOrder="10" showInDefault="1" showInContainer="1" showInStore="1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<thesaurus>
<general>
<max_rewrites>2</max_rewrites>
<max_rewritten_queries>0</max_rewritten_queries>
</general>
<synonyms>
<enable>1</enable>
Expand Down
5 changes: 5 additions & 0 deletions src/module-elasticsuite-thesaurus/i18n/de_DE.csv
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"Total of %1 record(s) were deleted.","%1 Eintrag / Einträge wurden gelöscht."
"You saved the thesaurus %1.","Der Thesaurus %1 wurde gespeichert."
"Thesaurus Configuration","Thesaurus Einstellungen"
"General Configuration","General Configuration"
"Max Allowed Rewrites","Max Allowed Rewrites"
"Maximum number of thesaurus rules applied at a given time to a given search query to produce alternative queries. That number applies first to the synonyms rules and then the expansion rules. For instance if the setting's value is 2, it means each alternative query will be the result of the application of at most 2 synonyms rules and at most 2 expansion rules. But if you have 10 synonym rules and 5 expansion rules, they could all end up being applied by pairs. So be careful about augmenting this setting's value, especially if you already have a lot of rules with long lists of alternative terms.","Maximum number of thesaurus rules applied at a given time to a given search query to produce alternative queries. That number applies first to the synonyms rules and then the expansion rules. For instance if the setting's value is 2, it means each alternative query will be the result of the application of at most 2 synonyms rules and at most 2 expansion rules. But if you have 10 synonym rules and 5 expansion rules, they could all end up being applied by pairs. So be careful about augmenting this setting's value, especially if you already have a lot of rules with long lists of alternative terms."
"Max Alternative Search Queries","Max Alternative Search Queries"
"Maximum number of alternative search queries taken into account. Use this setting if you have performance issues arising on your cluster related to a huge volume of thesaurus rules. Defaults to 0 (no limitation).","Maximum number of alternative search queries taken into account. Use this setting if you have performance issues arising on your cluster related to a huge volume of thesaurus rules. Defaults to 0 (no limitation)."
"Synonyms Configuration","Synonyme Einstellungen"
"Enable Synonyms Search","Aktiviere Suche nach Synonymen"
"Synonyms Weight Divider","Verteilung der Gewichtung von Synonymen"
Expand Down
5 changes: 5 additions & 0 deletions src/module-elasticsuite-thesaurus/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ Synonyms,Synonyms
"Total of %1 record(s) were deleted.","Total of %1 record(s) were deleted."
"You saved the thesaurus %1.","You saved the thesaurus %1."
"Thesaurus Configuration","Thesaurus Configuration"
"General Configuration","General Configuration"
"Max Allowed Rewrites","Max Allowed Rewrites"
"Maximum number of thesaurus rules applied at a given time to a given search query to produce alternative queries. That number applies first to the synonyms rules and then the expansion rules. For instance if the setting's value is 2, it means each alternative query will be the result of the application of at most 2 synonyms rules and at most 2 expansion rules. But if you have 10 synonym rules and 5 expansion rules, they could all end up being applied by pairs. So be careful about augmenting this setting's value, especially if you already have a lot of rules with long lists of alternative terms.","Maximum number of thesaurus rules applied at a given time to a given search query to produce alternative queries. That number applies first to the synonyms rules and then the expansion rules. For instance if the setting's value is 2, it means each alternative query will be the result of the application of at most 2 synonyms rules and at most 2 expansion rules. But if you have 10 synonym rules and 5 expansion rules, they could all end up being applied by pairs. So be careful about augmenting this setting's value, especially if you already have a lot of rules with long lists of alternative terms."
"Max Alternative Search Queries","Max Alternative Search Queries"
"Maximum number of alternative search queries taken into account. Use this setting if you have performance issues arising on your cluster related to a huge volume of thesaurus rules. Defaults to 0 (no limitation).","Maximum number of alternative search queries taken into account. Use this setting if you have performance issues arising on your cluster related to a huge volume of thesaurus rules. Defaults to 0 (no limitation)."
"Synonyms Configuration","Synonyms Configuration"
"Enable Synonyms Search","Enable Synonyms Search"
"Synonyms Weight Divider","Synonyms Weight Divider"
Expand Down
5 changes: 5 additions & 0 deletions src/module-elasticsuite-thesaurus/i18n/fr_FR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ Synonyms,Synonymes
"Total of %1 record(s) were deleted.","%1 enregistrement(s) ont été supprimé(s)."
"You saved the thesaurus %1.","Thésaurus %1 sauvegardé."
"Thesaurus Configuration","Configuration du thésaurus"
"General Configuration","Configuration Générale"
"Max Allowed Rewrites","Nombre maximum de remplacements"
"Maximum number of thesaurus rules applied at a given time to a given search query to produce alternative queries. That number applies first to the synonyms rules and then the expansion rules. For instance if the setting's value is 2, it means each alternative query will be the result of the application of at most 2 synonyms rules and at most 2 expansion rules. But if you have 10 synonym rules and 5 expansion rules, they could all end up being applied by pairs. So be careful about augmenting this setting's value, especially if you already have a lot of rules with long lists of alternative terms.","Nombre maximal de règles de thésaurus appliquées consécutivement à une requête de recherche pour générer des requêtes alternatives. Ce nombre s'applique d'abord aux règles de synonymes puis aux règles d'expansion. Par exemple si la valeur du paramètre est 2, chaque requête alternative sera le résultat de l'application d'au plus 2 règles de synonymes et de 2 règles d'expansion. Mais si vous avez 10 règles de synonymes et 5 règles d'expansions, elles pourraient au final être toutes appliquées par paires. Soyez donc prudent sur l'augmentation de ce paramètre, particulièrement si vous avez déjà beaucoup de règles avec de grandes listes de termes alternatifs."
"Max Alternative Search Queries","Nombre maximum de recherches alternatives"
"Maximum number of alternative search queries taken into account. Use this setting if you have performance issues arising on your cluster related to a huge volume of thesaurus rules. Defaults to 0 (no limitation).","Nombre de recherches alternatives réellement prises en compte. Utilisez ce paramètre si vous rencontrez des problèmes de performance de votre cluster liés à un énorme volume de règles de thésaurus. Valeur par défaut: 0 (pas de limitation)."
"Synonyms Configuration","Configuration des synonymes"
"Enable Synonyms Search","Activer la recherche par synonyme"
"Synonyms Weight Divider","Pondérateur de poids pour les synonymes"
Expand Down
5 changes: 5 additions & 0 deletions src/module-elasticsuite-thesaurus/i18n/nl_NL.csv
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"Total of %1 record(s) were deleted.","Totaal van %1 record(s) werden verwijderd."
"You saved the thesaurus %1.","Je hebt de thesaurus %1 gered."
"Thesaurus Configuration","Thesaurus configuratie"
"General Configuration","General Configuration"
"Max Allowed Rewrites","Max Allowed Rewrites"
"Maximum number of thesaurus rules applied at a given time to a given search query to produce alternative queries. That number applies first to the synonyms rules and then the expansion rules. For instance if the setting's value is 2, it means each alternative query will be the result of the application of at most 2 synonyms rules and at most 2 expansion rules. But if you have 10 synonym rules and 5 expansion rules, they could all end up being applied by pairs. So be careful about augmenting this setting's value, especially if you already have a lot of rules with long lists of alternative terms.","Maximum number of thesaurus rules applied at a given time to a given search query to produce alternative queries. That number applies first to the synonyms rules and then the expansion rules. For instance if the setting's value is 2, it means each alternative query will be the result of the application of at most 2 synonyms rules and at most 2 expansion rules. But if you have 10 synonym rules and 5 expansion rules, they could all end up being applied by pairs. So be careful about augmenting this setting's value, especially if you already have a lot of rules with long lists of alternative terms."
"Max Alternative Search Queries","Max Alternative Search Queries"
"Maximum number of alternative search queries taken into account. Use this setting if you have performance issues arising on your cluster related to a huge volume of thesaurus rules. Defaults to 0 (no limitation).","Maximum number of alternative search queries taken into account. Use this setting if you have performance issues arising on your cluster related to a huge volume of thesaurus rules. Defaults to 0 (no limitation)."
"Synonyms Configuration","Configuratie synoniemen"
"Enable Synonyms Search","Synoniemen zoeken inschakelen"
"Synonyms Weight Divider","Synoniemen Gewicht Verdeler"
Expand Down

0 comments on commit ae1c68b

Please sign in to comment.