Skip to content

Commit

Permalink
Merge branch '2.11.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
rbayet committed Sep 24, 2023
2 parents b8fedfa + 3905237 commit a72549d
Show file tree
Hide file tree
Showing 32 changed files with 422 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ReaderPlugin
const XML_CATEGORY_NAME_WEIGHT = 'smile_elasticsuite_catalogsearch_settings/catalogsearch/category_name_weight';

/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
* @var ScopeConfigInterface
*/
private $scopeConfig;

Expand Down
3 changes: 1 addition & 2 deletions src/module-elasticsuite-catalog/etc/db_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@
<column name="facet_sort_order"
xsi:type="varchar"
length="30"
default="_count"
nullable="false"
nullable="true"
comment="The pattern to display facet values"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="entity_id"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public function isSearchable();
*/
public function isSearchableReference();

/**
* Is the field searchable and using an edge ngram based analyzer.
*/
public function isSearchableEdgeNgram();

/**
* Is the field filterable in navigation.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface MappingInterface
const DEFAULT_SPELLING_FIELD = 'spelling';
const DEFAULT_AUTOCOMPLETE_FIELD = 'autocomplete';
const DEFAULT_REFERENCE_FIELD = 'reference';
const DEFAULT_EDGE_NGRAM_FIELD = 'edge_ngram';

/**
* List of the properties of the mapping.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,40 @@ public function isUsingAllTokens();
*/
public function isUsingReferenceAnalyzer();

/**
* Check if the term vectors request should also include the edge ngram analyzer(s) collector field.
*
* @return bool
*/
public function isUsingEdgeNgramAnalyzer();

/**
* If we should use the default analyzer of each field when building the exact match filter query.
*
* @return bool
*/
public function isUsingDefaultAnalyzerInExactMatchFilter();

/**
* Are the exact match boosts on whitespace and sortable version of searchable attributes/fields
* customized.
*
* @return bool
*/
public function areExactMatchSingleTermBoostsCustomized();

/**
* Returns the exact match boost for whitespace version of searchable attributes/fields,
* used instead of the shingle version of attributes/fields when a single term is searched.
*
* @return int
*/
public function getExactMatchSingleTermPhraseMatchBoost();

/**
* Returns the exact match boost for sortable version of searchable+sortable attributes/fields.
*
* @return int
*/
public function getExactMatchSingleTermSortableBoost();
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,11 @@ public function isUsingAllTokens();
* @return boolean
*/
public function isUsingReference();

/**
* Should the spellcheck request target the 'edge_ngram' collector field.
*
* @return boolean
*/
public function isUsingEdgeNgram();
}
6 changes: 6 additions & 0 deletions src/module-elasticsuite-core/Index/Mapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ class Mapping implements MappingInterface
FieldInterface::ANALYZER_WHITESPACE,
FieldInterface::ANALYZER_SHINGLE,
],
self::DEFAULT_EDGE_NGRAM_FIELD => [
FieldInterface::ANALYZER_EDGE_NGRAM,
FieldInterface::ANALYZER_WHITESPACE,
FieldInterface::ANALYZER_SHINGLE,
],
];

/**
Expand All @@ -78,6 +83,7 @@ class Mapping implements MappingInterface
'isSearchable' => self::DEFAULT_SEARCH_FIELD,
'isUsedInSpellcheck' => self::DEFAULT_SPELLING_FIELD,
'isSearchableReference' => self::DEFAULT_REFERENCE_FIELD,
'isSearchableEdgeNgram' => self::DEFAULT_EDGE_NGRAM_FIELD,
];

/**
Expand Down
8 changes: 8 additions & 0 deletions src/module-elasticsuite-core/Index/Mapping/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ public function isSearchableReference(): bool
return ($this->isSearchable() && (FieldInterface::ANALYZER_REFERENCE === $this->config['default_search_analyzer']));
}

/**
* {@inheritDoc}
*/
public function isSearchableEdgeNgram(): bool
{
return ($this->isSearchable() && (FieldInterface::ANALYZER_EDGE_NGRAM === $this->config['default_search_analyzer']));
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class ComposerInformation extends \Magento\Framework\Composer\ComposerInformatio
*/
private $composerFactory;


/**
* @param \Magento\Framework\Composer\ComposerFactory $composerFactory Composer Factory
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function getSpellingType(RequestInterface $request)

$spellingType = $this->cacheHelper->loadCache($cacheKey);

if ($spellingType === false) {
if (true || $spellingType === false) {
$spellingType = $this->loadSpellingType($request);
$this->cacheHelper->saveCache($cacheKey, $spellingType, [$request->getIndex(), ScopePool::CACHE_TAG]);
}
Expand Down Expand Up @@ -169,6 +169,11 @@ private function getTermVectors(RequestInterface $request)
$doc['doc'][MappingInterface::DEFAULT_REFERENCE_FIELD] = $request->getQueryText();
}

if ($request->isUsingEdgeNgram()) {
$doc['fields'][] = MappingInterface::DEFAULT_EDGE_NGRAM_FIELD . "." . FieldInterface::ANALYZER_EDGE_NGRAM;
$doc['doc'][MappingInterface::DEFAULT_EDGE_NGRAM_FIELD] = $request->getQueryText();
}

$docs = [];

// Compute the mtermvector query on all shards to ensure exhaustive results.
Expand Down Expand Up @@ -214,6 +219,8 @@ private function parseTermVectors($termVectors, $cutoffFrequencyLimit, $useAllTo
$type = 'exact';
} elseif (in_array(FieldInterface::ANALYZER_REFERENCE, $positionStat['analyzers'])) {
$type = 'exact';
} elseif (in_array(FieldInterface::ANALYZER_EDGE_NGRAM, $positionStat['analyzers'])) {
$type = 'exact';
}
}
$queryTermStats[$type]++;
Expand All @@ -239,7 +246,12 @@ private function parseTermVectors($termVectors, $cutoffFrequencyLimit, $useAllTo
private function extractTermStatsByPosition($termVectors, $useAllTokens = false)
{
$statByPosition = [];
$analyzers = [FieldInterface::ANALYZER_STANDARD, FieldInterface::ANALYZER_WHITESPACE, FieldInterface::ANALYZER_REFERENCE];
$analyzers = [
FieldInterface::ANALYZER_STANDARD,
FieldInterface::ANALYZER_WHITESPACE,
FieldInterface::ANALYZER_REFERENCE,
FieldInterface::ANALYZER_EDGE_NGRAM,
];

if (is_array($termVectors) && isset($termVectors['docs'])) {
foreach ($termVectors['docs'] as $termVector) {
Expand Down
1 change: 1 addition & 0 deletions src/module-elasticsuite-core/Search/Request/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ private function getSpellingType(ContainerConfigurationInterface $containerConfi
'cutoffFrequency' => $containerConfig->getRelevanceConfig()->getCutOffFrequency(),
'isUsingAllTokens' => $containerConfig->getRelevanceConfig()->isUsingAllTokens(),
'isUsingReference' => $containerConfig->getRelevanceConfig()->isUsingReferenceAnalyzer(),
'isUsingEdgeNgram' => $containerConfig->getRelevanceConfig()->isUsingEdgeNgramAnalyzer(),
];

$spellcheckRequest = $this->spellcheckRequestFactory->create($spellcheckRequestParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
/**
* Relevance Configuration object
*
* @SuppressWarnings(PHPMD.TooManyFields)
*
* @category Smile
* @package Smile\ElasticsuiteCore
* @author Romain Ruaud <romain.ruaud@smile.fr>
Expand Down Expand Up @@ -90,6 +92,26 @@ class RelevanceConfig implements RelevanceConfigurationInterface
*/
private $useReferenceAnalyzer;

/**
* @var boolean
*/
private $useEdgeNgramAnalyzer;

/**
* @var boolean
*/
private $exactMatchSingleTermBoostsCustomized;

/**
* @var integer|null
*/
private $exactMatchSingleTermPhraseMatchBoost;

/**
* @var integer|null
*/
private $exactMatchSingleTermSortableBoost;

/**
* RelevanceConfiguration constructor.
*
Expand All @@ -114,6 +136,17 @@ class RelevanceConfig implements RelevanceConfigurationInterface
* @param boolean $useAllTokens Whether to take into account all term vector tokens
* @param boolean $useReferenceAnalyzer Whether to include the collector field associated
* with the reference analyzer in term vectors request
* @param boolean $useEdgeNgramAnalyzer Whether to include the collector field associated
* with the edge ngram analyzer(s) in the term vectors
* request
* @param boolean $exactMatchSingleTermBoostsCustomized Are the exact match boost values on whitespace
* and sortable fields customized.
* @param int|null $exactMatchSingleTermPhraseMatchBoost The whitespace boost value for exact match,
* or null if the default (phrase match boost value)
* should apply
* @param int|null $exactMatchSingleTermSortableBoost The sortable boost value for exact match,
* or null if the default (twice the phrase match
* boost value) should apply
*/
public function __construct(
$minimumShouldMatch,
Expand All @@ -128,7 +161,11 @@ public function __construct(
$useReferenceInExactMatchFilter = false,
$useDefaultAnalyzerInExactMatchFilter = false,
$useAllTokens = false,
$useReferenceAnalyzer = false
$useReferenceAnalyzer = false,
$useEdgeNgramAnalyzer = false,
$exactMatchSingleTermBoostsCustomized = false,
$exactMatchSingleTermPhraseMatchBoost = null,
$exactMatchSingleTermSortableBoost = null
) {
$this->minimumShouldMatch = $minimumShouldMatch;
$this->tieBreaker = $tieBreaker;
Expand All @@ -142,7 +179,11 @@ public function __construct(
$this->useReferenceInExactMatchFilter = $useReferenceInExactMatchFilter;
$this->useAllTokens = $useAllTokens;
$this->useReferenceAnalyzer = $useReferenceAnalyzer;
$this->useEdgeNgramAnalyzer = $useEdgeNgramAnalyzer;
$this->useDefaultAnalyzerInExactMatchFilter = $useDefaultAnalyzerInExactMatchFilter;
$this->exactMatchSingleTermBoostsCustomized = $exactMatchSingleTermBoostsCustomized;
$this->exactMatchSingleTermPhraseMatchBoost = $exactMatchSingleTermPhraseMatchBoost;
$this->exactMatchSingleTermSortableBoost = $exactMatchSingleTermSortableBoost;
}

/**
Expand Down Expand Up @@ -262,4 +303,36 @@ public function isUsingReferenceAnalyzer()
{
return (bool) $this->useReferenceAnalyzer;
}

/**
* {@inheritDoc}
*/
public function isUsingEdgeNgramAnalyzer()
{
return (bool) $this->useEdgeNgramAnalyzer;
}

/**
* {@inheritDoc}
*/
public function areExactMatchSingleTermBoostsCustomized()
{
return (bool) $this->exactMatchSingleTermBoostsCustomized;
}

/**
* {@inheritDoc}
*/
public function getExactMatchSingleTermPhraseMatchBoost()
{
return (int) $this->exactMatchSingleTermPhraseMatchBoost;
}

/**
* {@inheritDoc}
*/
public function getExactMatchSingleTermSortableBoost()
{
return (int) $this->exactMatchSingleTermSortableBoost;
}
}
Loading

0 comments on commit a72549d

Please sign in to comment.