Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Analysis] Allow ignoring leading, trailing and consecutive zeroes in… #3243

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/module-elasticsuite-core/Helper/IndexSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use Magento\Framework\App\ObjectManager;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Model\ScopeInterface;
use Zend_Date;

Expand All @@ -40,6 +41,18 @@ class IndexSettings extends AbstractConfiguration
*/
const INDICES_SETTINGS_CONFIG_XML_PREFIX = 'indices_settings';

/**
* Location of Elasticsuite analysis settings configuration.
*
* @var string
*/
const ANALYSIS_CONFIG_XML_PREFIX = 'smile_elasticsuite_core_analysis_settings';

/**
* @var string
*/
const REFERENCE_ANALYZER_CONFIG_XML_PREFIX = 'reference_analyzer';

/**
* @var string
*/
Expand Down Expand Up @@ -378,6 +391,21 @@ public function getIndicesSettingsConfigParam($configField)
return $this->getElasticSuiteConfigParam($path);
}

/**
* Read config flag under the path smile_elasticsuite_core_analysis_settings/reference_analyzer.
*
* @param string $configFlag Config flag name.
* @param integer|string|StoreInterface $store Store.
*
* @return mixed
*/
public function getReferenceAnalyzerConfigFlag($configFlag, $store)
{
$path = self::ANALYSIS_CONFIG_XML_PREFIX . '/' . self::REFERENCE_ANALYZER_CONFIG_XML_PREFIX . '/' . $configFlag;

return $this->scopeConfig->isSetFlag($path, ScopeInterface::SCOPE_STORE, $store);
}

/**
* Retrieve a configuration value by its key.
*
Expand Down
21 changes: 20 additions & 1 deletion src/module-elasticsuite-core/Index/IndexSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,27 @@ public function createIndexNameFromIdentifier($indexIdentifier, $store)
public function getAnalysisSettings($store)
{
$language = $this->helper->getLanguageCode($store);
$settings = $this->analysisConfig->get($language);

if (is_array($settings)
&& array_key_exists('analyzer', $settings)
&& array_key_exists('reference', $settings['analyzer'])
&& array_key_exists('filter', $settings['analyzer']['reference'])
) {
$referenceFilters = array_values($settings['analyzer']['reference']['filter'] ?? []);
if (!$this->helper->getReferenceAnalyzerConfigFlag('trim_leading_zeroes', $store)) {
$referenceFilters = array_diff($referenceFilters, ['trim_leading_zeroes']);
}
if (!$this->helper->getReferenceAnalyzerConfigFlag('trim_trailing_zeroes', $store)) {
$referenceFilters = array_diff($referenceFilters, ['trim_trailing_zeroes']);
}
if (!$this->helper->getReferenceAnalyzerConfigFlag('reduce_zeroes', $store)) {
$referenceFilters = array_diff($referenceFilters, ['reduce_zeroes']);
}
$settings['analyzer']['reference']['filter'] = array_values($referenceFilters);
}

return $this->analysisConfig->get($language);
return $settings;
}

/**
Expand Down
26 changes: 26 additions & 0 deletions src/module-elasticsuite-core/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,32 @@

</section>

<section id="smile_elasticsuite_core_analysis_settings" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
<class>separator-top</class>
<label>Analyzers Settings</label>
<tab>smile_elasticsuite</tab>
<resource>Magento_Catalog::config_smile_elasticsuite_core_analysis_settings</resource>

<group id="reference_analyzer" translate="label" type="text" sortOrder="80" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Reference analyzer configuration</label>
<field id="trim_leading_zeroes" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Remove leading zeroes of numeric parts</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment><![CDATA[If enabled, when indexing a reference like "VT0009", it will be as if "VT9" was indexed instead (leading to independant elements "VT", "9" and "VT9" in the search index). This will allow someone searching for "vt9" or "vt 9" to find the product with the exact "VT0009" sku.]]></comment>
</field>
<field id="trim_trailing_zeroes" translate="label comment" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Remove trailing zeroes of numeric parts</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment><![CDATA[If enabled, when indexing a reference like "DC3000", it will be as if "DC3" was indexed instead (leading to independant elements "DC", "3" and "DC3" in the search index). This will allow someone searching for "dc3" or "dc 3" to find the product with the exact "DC3000" sku.]]></comment>
</field>
<field id="reduce_zeroes" translate="label comment" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Reduce series of contiguous zeroes in numeric parts</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment><![CDATA[If enabled, when indexing a reference like "PL20004", it will be as if "PL204" was indexed instead (leading to independant elements "PL", "204" and "PL204" in the search index). This will allow someone searching for "pl204", "pl 204", "pl2004" or "pl 2004" to find the product with the exact "PL2004" sku.]]></comment>
</field>
</group>
</section>

<section id="smile_elasticsuite_autocomplete_settings" translate="label" type="text" sortOrder="1000" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Autocomplete</label>
<tab>smile_elasticsuite</tab>
Expand Down
8 changes: 8 additions & 0 deletions src/module-elasticsuite-core/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
</indices_settings>
</smile_elasticsuite_core_base_settings>

<smile_elasticsuite_core_analysis_settings>
<reference_analyzer>
<trim_leading_zeroes>0</trim_leading_zeroes>
<trim_trailing_zeroes>0</trim_trailing_zeroes>
<reduce_zeroes>0</reduce_zeroes>
</reference_analyzer>
</smile_elasticsuite_core_analysis_settings>

<smile_elasticsuite_autocomplete_settings>
<term_autocomplete>
<max_size>3</max_size>
Expand Down
15 changes: 15 additions & 0 deletions src/module-elasticsuite-core/etc/elasticsuite_analysis.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@
<min_gram>3</min_gram>
<max_gram>20</max_gram>
</filter>
<filter name="trim_leading_zeroes" type="pattern_replace" language="default">
<pattern><![CDATA[^0+]]></pattern>
<replacement><![CDATA[]]></replacement>
</filter>
<filter name="trim_trailing_zeroes" type="pattern_replace" language="default">
<pattern><![CDATA[0+$]]></pattern>
<replacement><![CDATA[]]></replacement>
</filter>
<filter name="reduce_zeroes" type="pattern_replace" language="default">
<pattern><![CDATA[0+]]></pattern>
<replacement><![CDATA[0]]></replacement>
</filter>
</filters>

<analyzers>
Expand Down Expand Up @@ -222,6 +234,9 @@
<filter ref="trim" />
<filter ref="elision" />
<filter ref="reference_word_delimiter" />
<filter ref="trim_leading_zeroes" />
<filter ref="trim_trailing_zeroes" />
<filter ref="reduce_zeroes" />
<filter ref="lowercase" />
<filter ref="reference_shingle" />
</filters>
Expand Down
8 changes: 8 additions & 0 deletions src/module-elasticsuite-core/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,11 @@ Autocomplete,Autocomplete
"Indices and fields configuration, redundant computations (queries spellchecking, synonyms).","Indices and fields configuration, redundant computations (queries spellchecking, synonyms)."
"ver. %1","ver. %1"
"(on %1 ver. %2)","(on %1 ver. %2)"
"Analyzers Settings","Analyzers Settings"
"Reference analyzer configuration","Reference analyzer configuration"
"Remove leading zeroes of numeric parts","Remove leading zeroes of numeric parts"
"If enabled, when indexing a reference like ""VT0009"", it will be as if ""VT9"" was indexed instead (leading to independant elements ""VT"", ""9"" and ""VT9"" in the search index). This will allow someone searching for ""vt9"" or ""vt 9"" to find the product with the exact ""VT0009"" sku.","If enabled, when indexing a reference like ""VT0009"", it will be as if ""VT9"" was indexed instead (leading to independant elements ""VT"", ""9"" and ""VT9"" in the search index). This will allow someone searching for ""vt9"" or ""vt 9"" to find the product with the exact ""VT0009"" sku."
"Remove trailing zeroes of numeric parts","Remove trailing zeroes of numeric parts"
"If enabled, when indexing a reference like ""DC3000"", it will be as if ""DC3"" was indexed instead (leading to independant elements ""DC"", ""3"" and ""DC3"" in the search index). This will allow someone searching for ""dc3"" or ""dc 3"" to find the product with the exact ""DC3000"" sku.","If enabled, when indexing a reference like ""DC3000"", it will be as if ""DC3"" was indexed instead (leading to independant elements ""DC"", ""3"" and ""DC3"" in the search index). This will allow someone searching for ""dc3"" or ""dc 3"" to find the product with the exact ""DC3000"" sku."
"Reduce series of contiguous zeroes in numeric parts","Reduce series of contiguous zeroes in numeric parts"
"If enabled, when indexing a reference like ""PL20004"", it will be as if ""PL204"" was indexed instead (leading to independant elements ""PL"", ""204"" and ""PL204"" in the search index). This will allow someone searching for ""pl204"", ""pl 204"", ""pl2004"" or ""pl 2004"" to find the product with the exact ""PL2004"" sku.","If enabled, when indexing a reference like ""PL20004"", it will be as if ""PL204"" was indexed instead (leading to independant elements ""PL"", ""204"" and ""PL204"" in the search index). This will allow someone searching for ""pl204"", ""pl 204"", ""pl2004"" or ""pl 2004"" to find the product with the exact ""PL2004"" sku."
8 changes: 8 additions & 0 deletions src/module-elasticsuite-core/i18n/fr_FR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,11 @@ General,Général
"When set to 'yes', the fuzzy queries will use the default value for the Minimum Should Match, defined in Relevance Configuration > Fulltext Base Settings > Minimum Should Match.","Si réglé sur 'oui', la recherche approchante utilisera comme valeur pour le Minimum Should Match, celle définie à l'emplacement Configuration de la pertinence > Paramétrage de base de la recherche fulltext > Minimum Should Match."
"ver. %1","ver. %1"
"(on %1 ver. %2)","(sur %1 ver. %2)"
"Analyzers Settings","Paramètres des analyseurs"
"Reference analyzer configuration","Configuration de l'analyseur reference"
"Remove leading zeroes of numeric parts","Supprimer les zéros à gauche des parties numériques"
"If enabled, when indexing a reference like ""VT0009"", it will be as if ""VT9"" was indexed instead (leading to independant elements ""VT"", ""9"" and ""VT9"" in the search index). This will allow someone searching for ""vt9"" or ""vt 9"" to find the product with the exact ""VT0009"" sku.","Si activé, en indexant une référence comme ""VT0009"", le résultat sera comme si ""VT9"" était indexé à la place (menant à l'indexation des éléments indépendants ""VT"", ""9"" et ""VT9""). Cela permettra à quelqu'un cherchant ""vt9"" ou ""vt 9"" de trouver le produit avec le sku exact ""VT0009""."
"Remove trailing zeroes of numeric parts","Supprimer les zéros à droite des parties numériques"
"If enabled, when indexing a reference like ""DC3000"", it will be as if ""DC3"" was indexed instead (leading to independant elements ""DC"", ""3"" and ""DC3"" in the search index). This will allow someone searching for ""dc3"" or ""dc 3"" to find the product with the exact ""DC3000"" sku.","Si activé, en indexant une référence comme ""DC3000"", le résultat sera comme si ""DC3"" était indexé à la place (menant à l'indexation des éléments indépendants ""DC"", ""3"" et ""DC3""). Cela permettra à quelqu'un cherchant ""dc3"" ou ""dc 3"" de trouver le produit avec le sku exact ""DC3000""."
"Reduce series of contiguous zeroes in numeric parts","Réduire les séries de zéros contigus des parties numériques"
"If enabled, when indexing a reference like ""PL20004"", it will be as if ""PL204"" was indexed instead (leading to independant elements ""PL"", ""204"" and ""PL204"" in the search index). This will allow someone searching for ""pl204"", ""pl 204"", ""pl2004"" or ""pl 2004"" to find the product with the exact ""PL2004"" sku.","Si activé, en indexant une référence comme ""PL20004"", le résultat sera comme si ""PL204"" était indexé à la place (menant à l'indexation des éléments indépendants ""PL"", ""204"" et ""PL204""). Cela permettra à quelqu'un cherchant ""pl204"", ""pl 204"", ""pl2004"" ou ""pl 2004"" de trouver le produit avec le sku exact ""PL2004""."
Loading