p59 + p60
This commit is contained in:
@@ -22,6 +22,7 @@ final class SearchRepairConfig
|
||||
private readonly int $minPrimaryResultsWithoutRepair,
|
||||
private readonly array $config,
|
||||
private readonly DomainVocabularyConfig $vocabulary,
|
||||
private readonly ?GenreConfig $genreConfig = null,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -52,36 +53,44 @@ final class SearchRepairConfig
|
||||
|
||||
public function isDirectProductAttributeLookupRepairEnabled(): bool
|
||||
{
|
||||
return $this->requiredBool('direct_product_attribute_lookup.enabled');
|
||||
return $this->genreBool('search_repair.direct_product_attribute_lookup.enabled')
|
||||
?? $this->requiredBool('direct_product_attribute_lookup.enabled');
|
||||
}
|
||||
|
||||
public function getDirectProductAttributeLookupMinTokens(): int
|
||||
{
|
||||
return $this->requiredPositiveInt('direct_product_attribute_lookup.min_query_tokens_after_cleanup');
|
||||
$genreValue = $this->genreInt('search_repair.direct_product_attribute_lookup.min_query_tokens_after_cleanup');
|
||||
|
||||
return $genreValue !== null && $genreValue > 0
|
||||
? $genreValue
|
||||
: $this->requiredPositiveInt('direct_product_attribute_lookup.min_query_tokens_after_cleanup');
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function getDirectProductAttributeLookupProductTypeTerms(): array
|
||||
{
|
||||
return $this->configOrVocabularyStringList(
|
||||
'direct_product_attribute_lookup.product_type_terms',
|
||||
'search_repair.direct_product_type_terms'
|
||||
);
|
||||
return $this->genreStringList('product_attributes.direct_attribute_cleanup.product_type_terms')
|
||||
?: $this->configOrVocabularyStringList(
|
||||
'direct_product_attribute_lookup.product_type_terms',
|
||||
'search_repair.direct_product_type_terms'
|
||||
);
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function getDirectProductAttributeLookupStopTerms(): array
|
||||
{
|
||||
return $this->configOrVocabularyStringList(
|
||||
'direct_product_attribute_lookup.stop_terms',
|
||||
'search_repair.direct_product_attribute_stop_terms'
|
||||
);
|
||||
return $this->genreStringList('product_attributes.direct_attribute_cleanup.stop_terms')
|
||||
?: $this->configOrVocabularyStringList(
|
||||
'direct_product_attribute_lookup.stop_terms',
|
||||
'search_repair.direct_product_attribute_stop_terms'
|
||||
);
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function getDirectProductAttributeLookupComparativeConstraintPatterns(): array
|
||||
{
|
||||
return $this->requiredStringList('direct_product_attribute_lookup.comparative_constraint_patterns');
|
||||
return $this->genreStringList('product_attributes.direct_attribute_cleanup.comparative_constraint_patterns')
|
||||
?: $this->requiredStringList('direct_product_attribute_lookup.comparative_constraint_patterns');
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
@@ -116,7 +125,8 @@ final class SearchRepairConfig
|
||||
/** @return string[] */
|
||||
public function getSpecificModelCandidatePatterns(): array
|
||||
{
|
||||
return $this->requiredStringList('specific_model_candidate_patterns');
|
||||
return $this->genreStringList('search_repair.candidate_patterns.specific_model_candidate_patterns')
|
||||
?: $this->requiredStringList('specific_model_candidate_patterns');
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
@@ -135,40 +145,46 @@ final class SearchRepairConfig
|
||||
|
||||
public function getModelCandidatePattern(): string
|
||||
{
|
||||
return $this->requiredString('patterns.model_candidate');
|
||||
return $this->genreString('search_repair.candidate_patterns.patterns.model_candidate')
|
||||
?: $this->requiredString('patterns.model_candidate');
|
||||
}
|
||||
|
||||
public function getAccessoryCandidatePattern(): string
|
||||
{
|
||||
return $this->renderPatternTemplate(
|
||||
'patterns.accessory_candidate_template',
|
||||
['terms' => $this->patternAlternation($this->getAccessoryCandidateTerms())]
|
||||
['terms' => $this->patternAlternation($this->getAccessoryCandidateTerms())],
|
||||
'search_repair.candidate_patterns.patterns.accessory_candidate_template'
|
||||
);
|
||||
}
|
||||
|
||||
public function getRequestedAccessoryCodePattern(): string
|
||||
{
|
||||
return $this->requiredString('patterns.requested_accessory_code');
|
||||
return $this->genreString('search_repair.candidate_patterns.patterns.requested_accessory_code')
|
||||
?: $this->requiredString('patterns.requested_accessory_code');
|
||||
}
|
||||
|
||||
public function getAccessoryOrBundlePattern(): string
|
||||
{
|
||||
return $this->renderPatternTemplate(
|
||||
'patterns.accessory_or_bundle_template',
|
||||
['terms' => $this->patternAlternation($this->getAccessoryOrBundleTerms())]
|
||||
['terms' => $this->patternAlternation($this->getAccessoryOrBundleTerms())],
|
||||
'search_repair.candidate_patterns.patterns.accessory_or_bundle_template'
|
||||
);
|
||||
}
|
||||
|
||||
public function getModelLikePattern(): string
|
||||
{
|
||||
return $this->requiredString('patterns.model_like');
|
||||
return $this->genreString('search_repair.candidate_patterns.patterns.model_like')
|
||||
?: $this->requiredString('patterns.model_like');
|
||||
}
|
||||
|
||||
public function getSpecificityBoostPattern(): string
|
||||
{
|
||||
return $this->renderPatternTemplate(
|
||||
'patterns.specificity_boost_template',
|
||||
['terms' => $this->patternAlternation($this->getSpecificityBoostTerms())]
|
||||
['terms' => $this->patternAlternation($this->getSpecificityBoostTerms())],
|
||||
'search_repair.candidate_patterns.patterns.specificity_boost_template'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -286,6 +302,27 @@ final class SearchRepairConfig
|
||||
);
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
private function genreStringList(string $path): array
|
||||
{
|
||||
return $this->genreConfig?->getValueStringList($path) ?? [];
|
||||
}
|
||||
|
||||
private function genreString(string $path): string
|
||||
{
|
||||
return $this->genreConfig?->getValueString($path) ?? '';
|
||||
}
|
||||
|
||||
private function genreBool(string $path): ?bool
|
||||
{
|
||||
return $this->genreConfig?->getValueBool($path);
|
||||
}
|
||||
|
||||
private function genreInt(string $path): ?int
|
||||
{
|
||||
return $this->genreConfig?->getValueInt($path);
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
private function configOrVocabularyStringList(string $configKey, string $vocabularyPath): array
|
||||
{
|
||||
@@ -305,9 +342,12 @@ final class SearchRepairConfig
|
||||
}
|
||||
|
||||
/** @param array<string, string> $variables */
|
||||
private function renderPatternTemplate(string $path, array $variables): string
|
||||
private function renderPatternTemplate(string $path, array $variables, ?string $genrePath = null): string
|
||||
{
|
||||
$template = $this->requiredString($path);
|
||||
$template = $genrePath !== null ? $this->genreString($genrePath) : '';
|
||||
if ($template === '') {
|
||||
$template = $this->requiredString($path);
|
||||
}
|
||||
|
||||
foreach ($variables as $key => $value) {
|
||||
$template = str_replace('{' . $key . '}', $value, $template);
|
||||
|
||||
Reference in New Issue
Block a user