fix(advanced-search): D — correct @/| operator precedence (OR binds looser than AND)

Extracts a pure, testable AdvancedSearchUtilities.EvaluateBoolean that
splits on the outermost '|' (OR) before '@' (AND), so `a@b|c` now
evaluates as `(a&&b)||c` instead of the previous `a&&(b||c)`.
AdvancedSearchThreadWorker.EvaluateRecursive delegates to it, supplying
the entity-aware leaf evaluator.
This commit is contained in:
Kamron Batman 2026-07-19 21:42:59 -07:00
parent 8aa797a586
commit ed5e8d243f
3 changed files with 35 additions and 18 deletions

View file

@ -360,6 +360,24 @@ public static class AdvancedSearchUtilities
return false;
}
// OR ('|') binds looser than AND ('@'); split on the outermost OR first, then AND.
internal static bool EvaluateBoolean(ReadOnlySpan<char> expr, Func<string, bool> evalLeaf)
{
var orIndex = expr.IndexOf('|');
if (orIndex != -1)
{
return EvaluateBoolean(expr[..orIndex], evalLeaf) || EvaluateBoolean(expr[(orIndex + 1)..], evalLeaf);
}
var andIndex = expr.IndexOf('@');
if (andIndex != -1)
{
return EvaluateBoolean(expr[..andIndex], evalLeaf) && EvaluateBoolean(expr[(andIndex + 1)..], evalLeaf);
}
return evalLeaf(expr.Trim().ToString());
}
private static int GetEnumSize(Type enumType) =>
Type.GetTypeCode(Enum.GetUnderlyingType(enumType)) switch
{