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

@ -317,24 +317,8 @@ public class AdvancedSearchThreadWorker
}
}
private static bool EvaluateRecursive(IEntity entity, ReadOnlySpan<char> span)
{
var atIndex = span.IndexOf('@');
var orIndex = span.IndexOf('|');
if (atIndex == -1 && orIndex == -1)
{
return EvaluateSingleExpression(entity, span);
}
var result = atIndex != -1;
var splitIndex = result ? atIndex : orIndex;
var left = EvaluateRecursive(entity, span.Slice(0, splitIndex));
var right = EvaluateRecursive(entity, span.Slice(splitIndex + 1));
return result ? left && right : left || right;
}
private static bool EvaluateRecursive(IEntity entity, ReadOnlySpan<char> span) =>
AdvancedSearchUtilities.EvaluateBoolean(span, leaf => EvaluateSingleExpression(entity, leaf));
private static bool EvaluateSingleExpression(IEntity entity, ReadOnlySpan<char> expression)
{