Skip to content

Commit

Permalink
only normalize fuzzy match
Browse files Browse the repository at this point in the history
  • Loading branch information
kinosang committed Apr 22, 2024
1 parent c02737b commit bdaa833
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/Schemata.Resource.Foundation/Grammars/Operations/Match.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Linq.Expressions;
using Parlot;
using Schemata.Resource.Foundation.Grammars.Terms;
Expand All @@ -18,12 +17,6 @@ public abstract class Match : IBinary
}

public Expression ToExpression(Expression left, Expression right, Container ctx) {
var normalize = ctx.GetMethod(typeof(string), nameof(string.ToUpper), []);

if (normalize is null) {
throw new NotSupportedException("No string normalization method found");
}

var method = this switch {
ExactMatch => ctx.GetMethod(typeof(string), nameof(string.Contains), [typeof(string)]),
FuzzyMatch => ctx.GetMethod(typeof(string), nameof(string.Contains), [typeof(string)]),
Expand All @@ -40,7 +33,20 @@ public abstract class Match : IBinary
right = Expression.Call(right, "ToString", null);
}

return Expression.Call(Expression.Call(left, normalize, null), method, Expression.Call(right, normalize, null));
if (this is not FuzzyMatch) {
return Expression.Call(left, method, right);
}

var normalize = ctx.GetMethod(typeof(string), nameof(string.ToUpper), []);

if (normalize is null) {
return Expression.Call(left, method, right);
}

left = Expression.Call(left, normalize, null);
right = Expression.Call(right, normalize, null);

return Expression.Call(left, method, right);
}

public virtual ExpressionType? Type => null;
Expand Down

0 comments on commit bdaa833

Please sign in to comment.