p85
This commit is contained in:
@@ -317,6 +317,12 @@ final class AgentRunnerConfig
|
||||
return $this->genreConfig?->getValueInt($path);
|
||||
}
|
||||
|
||||
/** @return array<int|string, mixed> */
|
||||
private function genreArray(string $path): array
|
||||
{
|
||||
return $this->genreConfig?->getValueArray($path) ?? [];
|
||||
}
|
||||
|
||||
private function getRequiredInt(string $key): int
|
||||
{
|
||||
$value = $this->requiredValue($key);
|
||||
@@ -1390,6 +1396,107 @@ final class AgentRunnerConfig
|
||||
return $this->genreStringList('shop_query_runtime.semantic_shop_search_tokens.terms');
|
||||
}
|
||||
|
||||
public function isGenericDeviceQueryAnchorEnabled(): bool
|
||||
{
|
||||
return $this->genreBool('shop_query_runtime.generic_device_anchor.enabled') ?? false;
|
||||
}
|
||||
|
||||
public function shouldGenericDeviceQueryAnchorRemoveGenericDeviceTerms(): bool
|
||||
{
|
||||
return $this->genreBool('shop_query_runtime.generic_device_anchor.remove_generic_device_terms') ?? false;
|
||||
}
|
||||
|
||||
public function getGenericDeviceQueryAnchorTemplate(): string
|
||||
{
|
||||
return $this->genreString('shop_query_runtime.generic_device_anchor.template');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getGenericDeviceQueryAnchorTriggerTerms(): array
|
||||
{
|
||||
return $this->genreStringList('shop_query_runtime.generic_device_anchor.trigger_terms');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getGenericDeviceQueryAnchorSuppressTerms(): array
|
||||
{
|
||||
return $this->genreStringList('shop_query_runtime.generic_device_anchor.suppress_if_terms');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array{anchor: string, match_terms: string[]}>
|
||||
*/
|
||||
public function getGenericDeviceQueryAnchorRules(): array
|
||||
{
|
||||
$rules = [];
|
||||
|
||||
foreach ($this->genreArray('shop_query_runtime.generic_device_anchor.anchor_rules') as $rule) {
|
||||
if (!is_array($rule)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$anchor = $rule['anchor'] ?? '';
|
||||
if (!is_scalar($anchor)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$anchor = trim((string) $anchor);
|
||||
if ($anchor === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$rawMatchTerms = $rule['match_terms'] ?? [];
|
||||
if (!is_array($rawMatchTerms)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$matchTerms = [];
|
||||
foreach ($rawMatchTerms as $term) {
|
||||
if (!is_scalar($term)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$term = trim((string) $term);
|
||||
if ($term !== '' && !in_array($term, $matchTerms, true)) {
|
||||
$matchTerms[] = $term;
|
||||
}
|
||||
}
|
||||
|
||||
if ($matchTerms === []) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$rules[] = [
|
||||
'anchor' => $anchor,
|
||||
'match_terms' => $matchTerms,
|
||||
];
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getGenericDeviceQueryAnchorPositiveFilterTerms(): array
|
||||
{
|
||||
$terms = [];
|
||||
|
||||
foreach ($this->getGenericDeviceQueryAnchorRules() as $rule) {
|
||||
$terms[] = $rule['anchor'];
|
||||
$terms = array_merge($terms, $rule['match_terms']);
|
||||
}
|
||||
|
||||
return array_values(array_unique(array_filter(
|
||||
array_map(static fn(string $term): string => trim($term), $terms),
|
||||
static fn(string $term): bool => $term !== ''
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
|
||||
@@ -1371,6 +1371,47 @@ final readonly class RetriexEffectiveConfigProvider
|
||||
$this->validateRegexPatternList($positiveTokenFilter['adjacent_variant_patterns'] ?? [], 'genre.configuration_values.shop_query_runtime.positive_token_filter.adjacent_variant_patterns', $errors);
|
||||
}
|
||||
|
||||
$genericDeviceAnchor = is_array($shopQueryRuntime['generic_device_anchor'] ?? null)
|
||||
? $shopQueryRuntime['generic_device_anchor']
|
||||
: [];
|
||||
if ($genericDeviceAnchor !== []) {
|
||||
foreach (['enabled', 'remove_generic_device_terms'] as $boolKey) {
|
||||
if (array_key_exists($boolKey, $genericDeviceAnchor) && !is_bool($genericDeviceAnchor[$boolKey])) {
|
||||
$errors[] = sprintf('genre.configuration_values.shop_query_runtime.generic_device_anchor.%s must be boolean.', $boolKey);
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('template', $genericDeviceAnchor) && (!is_string($genericDeviceAnchor['template']) || trim($genericDeviceAnchor['template']) === '')) {
|
||||
$errors[] = 'genre.configuration_values.shop_query_runtime.generic_device_anchor.template must be a non-empty string.';
|
||||
}
|
||||
|
||||
$this->validateStringList($this->toList($genericDeviceAnchor['trigger_terms'] ?? []), 'genre.configuration_values.shop_query_runtime.generic_device_anchor.trigger_terms', $errors, $warnings);
|
||||
$this->validateStringList($this->toList($genericDeviceAnchor['suppress_if_terms'] ?? []), 'genre.configuration_values.shop_query_runtime.generic_device_anchor.suppress_if_terms', $errors, $warnings);
|
||||
|
||||
$anchorRules = $genericDeviceAnchor['anchor_rules'] ?? [];
|
||||
if ($anchorRules !== [] && !is_array($anchorRules)) {
|
||||
$errors[] = 'genre.configuration_values.shop_query_runtime.generic_device_anchor.anchor_rules must be a list.';
|
||||
} elseif (is_array($anchorRules)) {
|
||||
foreach ($anchorRules as $index => $rule) {
|
||||
if (!is_array($rule)) {
|
||||
$errors[] = sprintf('genre.configuration_values.shop_query_runtime.generic_device_anchor.anchor_rules.%s must be a map.', (string) $index);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!is_string($rule['anchor'] ?? null) || trim((string) ($rule['anchor'] ?? '')) === '') {
|
||||
$errors[] = sprintf('genre.configuration_values.shop_query_runtime.generic_device_anchor.anchor_rules.%s.anchor must be a non-empty string.', (string) $index);
|
||||
}
|
||||
|
||||
$this->validateStringList(
|
||||
$this->toList($rule['match_terms'] ?? []),
|
||||
sprintf('genre.configuration_values.shop_query_runtime.generic_device_anchor.anchor_rules.%s.match_terms', (string) $index),
|
||||
$errors,
|
||||
$warnings
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->collectGenreConfigurationValueSourcePaths($configurationValues) as $valuePath => $sourcePaths) {
|
||||
foreach ($sourcePaths as $sourcePath) {
|
||||
if (!isset($flattened[$sourcePath])) {
|
||||
|
||||
Reference in New Issue
Block a user