Trim unused rule evaluator helpers

This commit is contained in:
ajp_anton
2026-07-15 22:50:57 +00:00
parent b1348d13eb
commit 8211d988a3
@@ -147,18 +147,15 @@ public static class CategoryRuleEvaluator
var rawValue = term[(relation.Value.Index + relation.Value.Token.Length)..].Trim().Trim('"', '\'');
var result = relation.Value.Token switch
{
"contains" => FieldValues(field, facts, all: true).Any(v => ValueMatches(v, rawValue, IsLanguageField(field))),
"not_contains" => !FieldValues(field, facts, all: true).Any(v => ValueMatches(v, rawValue, IsLanguageField(field))),
"is" => FieldValues(field, facts, all: false) is { Length: 1 } values && ValueMatches(values[0], rawValue, IsLanguageField(field)),
"is_not" => !(FieldValues(field, facts, all: false) is { Length: 1 } values && ValueMatches(values[0], rawValue, IsLanguageField(field))),
"contains" => FieldValues(field, facts).Any(v => ValueMatches(v, rawValue, IsLanguageField(field))),
"not_contains" => !FieldValues(field, facts).Any(v => ValueMatches(v, rawValue, IsLanguageField(field))),
"is" => FieldValues(field, facts) is { Length: 1 } values && ValueMatches(values[0], rawValue, IsLanguageField(field)),
"is_not" => !(FieldValues(field, facts) is { Length: 1 } values && ValueMatches(values[0], rawValue, IsLanguageField(field))),
_ => false
};
return result;
}
private static bool EvaluateRequirement(UserCategoryRequirement requirement, FactsData facts)
=> TraceRequirement(requirement, facts).Result;
private static RequirementTrace TraceRequirement(UserCategoryRequirement requirement, FactsData facts)
{
var fields = RequirementFields(requirement);
@@ -196,12 +193,9 @@ public static class CategoryRuleEvaluator
fieldResults);
}
private static bool EvaluateRequirementField(string field, string relation, string[] expected, bool useOr, FactsData facts)
=> TraceRequirementField(field, relation, expected, useOr, facts).Result;
private static RequirementFieldTrace TraceRequirementField(string field, string relation, string[] expected, bool useOr, FactsData facts)
{
var actual = FieldValues(field, facts, all: true)
var actual = FieldValues(field, facts)
.Where(v => !string.IsNullOrWhiteSpace(v))
.Select(v => v.Trim())
.Distinct(StringComparer.OrdinalIgnoreCase)
@@ -271,7 +265,7 @@ public static class CategoryRuleEvaluator
return null;
}
private static string[] FieldValues(string field, FactsData facts, bool all)
private static string[] FieldValues(string field, FactsData facts)
{
field = field.Trim().ToLowerInvariant();
return field switch