Skip to content

Commit

Permalink
Reuse GetOperand for evaluating values
Browse files Browse the repository at this point in the history
  • Loading branch information
James Abbott committed Apr 25, 2024
1 parent a68e9ab commit de434ba
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/Redis.OM/Common/ExpressionParserUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,8 @@ private static object GetOperand(Expression expression)
{
MemberExpression me => GetValue(me.Member, ((ConstantExpression)me.Expression).Value),
ConstantExpression ce => ce.Value,
UnaryExpression ue when ue.NodeType == ExpressionType.Convert => Convert.ChangeType(GetOperand(ue.Operand), ue.Type),
MethodCallExpression me => me.Method.Invoke(me.Object, me.Arguments.Select(GetOperand).ToArray()),
_ => throw new InvalidOperationException("Could not determine value.")
};
}
Expand Down Expand Up @@ -1047,12 +1049,7 @@ private static string TranslateVectorRange(MethodCallExpression exp, List<object
bytes = vector.Embedding ?? throw new InvalidOperationException("Embedding was null");
}

var distance = exp.Arguments[2] switch
{
ConstantExpression ce => (double)ce.Value,
Expression e => (double)Expression.Lambda(e).Compile().DynamicInvoke(),
_ => throw new ArgumentException("The expression at position [2] was not an expression"),
};
var distance = (double)GetOperand(exp.Arguments[2]);

var distanceArgName = parameters.Count.ToString();
parameters.Add(distance);
Expand Down

0 comments on commit de434ba

Please sign in to comment.