public override FilterNode <ClrValue> Visit(BinaryOperatorNode nodeIn) { if (nodeIn.OperatorKind == BinaryOperatorKind.And) { return(ClrFilter.And(nodeIn.Left.Accept(this), nodeIn.Right.Accept(this))); } if (nodeIn.OperatorKind == BinaryOperatorKind.Or) { return(ClrFilter.Or(nodeIn.Left.Accept(this), nodeIn.Right.Accept(this))); } if (nodeIn.Left is SingleValueFunctionCallNode functionNode) { if (string.Equals(functionNode.Name, "geo.distance", StringComparison.OrdinalIgnoreCase) && nodeIn.OperatorKind == BinaryOperatorKind.LessThan) { var valueDistance = (double)ConstantWithTypeVisitor.Visit(nodeIn.Right).Value !; if (functionNode.Parameters.ElementAt(1) is not ConstantNode constantNode) { throw new NotSupportedException(); } if (constantNode.Value is not GeographyPoint geographyPoint) { throw new NotSupportedException(); } var property = PropertyPathVisitor.Visit(functionNode.Parameters.ElementAt(0)); return(ClrFilter.Lt(property, new FilterSphere(geographyPoint.Longitude, geographyPoint.Latitude, valueDistance))); } else { var regexFilter = Visit(functionNode); var value = ConstantWithTypeVisitor.Visit(nodeIn.Right); if (value.ValueType == ClrValueType.Boolean && value.Value is bool booleanRight) { if ((nodeIn.OperatorKind == BinaryOperatorKind.Equal && !booleanRight) || (nodeIn.OperatorKind == BinaryOperatorKind.NotEqual && booleanRight)) { regexFilter = ClrFilter.Not(regexFilter); } return(regexFilter); } } } else { if (nodeIn.OperatorKind == BinaryOperatorKind.NotEqual) { var value = ConstantWithTypeVisitor.Visit(nodeIn.Right); return(ClrFilter.Ne(PropertyPathVisitor.Visit(nodeIn.Left), value)); } if (nodeIn.OperatorKind == BinaryOperatorKind.Equal) { var value = ConstantWithTypeVisitor.Visit(nodeIn.Right); return(ClrFilter.Eq(PropertyPathVisitor.Visit(nodeIn.Left), value)); } if (nodeIn.OperatorKind == BinaryOperatorKind.LessThan) { var value = ConstantWithTypeVisitor.Visit(nodeIn.Right); return(ClrFilter.Lt(PropertyPathVisitor.Visit(nodeIn.Left), value)); } if (nodeIn.OperatorKind == BinaryOperatorKind.LessThanOrEqual) { var value = ConstantWithTypeVisitor.Visit(nodeIn.Right); return(ClrFilter.Le(PropertyPathVisitor.Visit(nodeIn.Left), value)); } if (nodeIn.OperatorKind == BinaryOperatorKind.GreaterThan) { var value = ConstantWithTypeVisitor.Visit(nodeIn.Right); return(ClrFilter.Gt(PropertyPathVisitor.Visit(nodeIn.Left), value)); } if (nodeIn.OperatorKind == BinaryOperatorKind.GreaterThanOrEqual) { var value = ConstantWithTypeVisitor.Visit(nodeIn.Right); return(ClrFilter.Ge(PropertyPathVisitor.Visit(nodeIn.Left), value)); } } throw new NotSupportedException(); }
public override FilterNode <ClrValue> Visit(BinaryOperatorNode nodeIn) { if (nodeIn.OperatorKind == BinaryOperatorKind.And) { return(ClrFilter.And(nodeIn.Left.Accept(this), nodeIn.Right.Accept(this))); } if (nodeIn.OperatorKind == BinaryOperatorKind.Or) { return(ClrFilter.Or(nodeIn.Left.Accept(this), nodeIn.Right.Accept(this))); } if (nodeIn.Left is SingleValueFunctionCallNode functionNode) { var regexFilter = Visit(functionNode); var value = ConstantWithTypeVisitor.Visit(nodeIn.Right); if (value.ValueType == ClrValueType.Boolean && value.Value is bool booleanRight) { if ((nodeIn.OperatorKind == BinaryOperatorKind.Equal && !booleanRight) || (nodeIn.OperatorKind == BinaryOperatorKind.NotEqual && booleanRight)) { regexFilter = ClrFilter.Not(regexFilter); } return(regexFilter); } } else { if (nodeIn.OperatorKind == BinaryOperatorKind.NotEqual) { var value = ConstantWithTypeVisitor.Visit(nodeIn.Right); return(ClrFilter.Ne(PropertyPathVisitor.Visit(nodeIn.Left), value)); } if (nodeIn.OperatorKind == BinaryOperatorKind.Equal) { var value = ConstantWithTypeVisitor.Visit(nodeIn.Right); return(ClrFilter.Eq(PropertyPathVisitor.Visit(nodeIn.Left), value)); } if (nodeIn.OperatorKind == BinaryOperatorKind.LessThan) { var value = ConstantWithTypeVisitor.Visit(nodeIn.Right); return(ClrFilter.Lt(PropertyPathVisitor.Visit(nodeIn.Left), value)); } if (nodeIn.OperatorKind == BinaryOperatorKind.LessThanOrEqual) { var value = ConstantWithTypeVisitor.Visit(nodeIn.Right); return(ClrFilter.Le(PropertyPathVisitor.Visit(nodeIn.Left), value)); } if (nodeIn.OperatorKind == BinaryOperatorKind.GreaterThan) { var value = ConstantWithTypeVisitor.Visit(nodeIn.Right); return(ClrFilter.Gt(PropertyPathVisitor.Visit(nodeIn.Left), value)); } if (nodeIn.OperatorKind == BinaryOperatorKind.GreaterThanOrEqual) { var value = ConstantWithTypeVisitor.Visit(nodeIn.Right); return(ClrFilter.Ge(PropertyPathVisitor.Visit(nodeIn.Left), value)); } } throw new NotSupportedException(); }