protected virtual QueryNode VisitLike(LikeNode node, ElasticSearchQueryOptimizerState state)
        {
            state.Boost = 1f;
            var node2 = Visit(node.LeftNode, state);

            return(new LikeNode(node2, Visit(node.RightNode, state), node.MinimumSimilarity, state.Boost));
        }
Esempio n. 2
0
        void BuildSql(LikeNode node)
        {
            if (node.Method == LikeMethod.Equals)
            {
                _builder.AddCondition(node.MemberNode.TableName, node.MemberNode.FieldName, _operationDictionary[ExpressionType.Equal], node.Value);
            }
            else
            {
                string value = node.Value;
                switch (node.Method)
                {
                case LikeMethod.StartsWith:
                    value = node.Value + _builder.Adapter.LikeChars();
                    break;

                case LikeMethod.EndsWith:
                    value = _builder.Adapter.LikeChars() + node.Value;
                    break;

                case LikeMethod.Contains:
                    value = _builder.Adapter.LikeChars() + node.Value + _builder.Adapter.LikeChars();
                    break;
                }
                _builder.AddLikeCondition(node.MemberNode.TableName, node.MemberNode.FieldName, value);
            }
        }
Esempio n. 3
0
        private void BuildSql(LikeNode node)
        {
            var value = string.Empty;

            switch (node.Method)
            {
            case LikeMethod.StartsWith:
                value = node.Value + "%";
                break;

            case LikeMethod.EndsWith:
                value = "%" + node.Value;
                break;

            case LikeMethod.Like:
            case LikeMethod.Contains:
                value = "%" + node.Value + "%";
                break;

            case LikeMethod.Equals:
                QueryByField(node.MemberNode.TableName, node.MemberNode.FieldName, operationDictionary[ExpressionType.Equal], node.Value);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            QueryByFieldLike(node.MemberNode.TableName, node.MemberNode.FieldName, value);
        }
Esempio n. 4
0
        private void BuildSql(LikeNode node)
        {
            if (node.Method == LikeMethod.Equals)
            {
                QueryByField(node.MemberNode.TableName, node.MemberNode.FieldName,
                             Helpers.Helper.GetOperator(ExpressionType.Equal), node.Value);
            }
            else
            {
                string value = node.Value;
                switch (node.Method)
                {
                case LikeMethod.StartsWith:
                    value = node.Value + "%";
                    break;

                case LikeMethod.EndsWith:
                    value = "%" + node.Value;
                    break;

                case LikeMethod.Contains:
                    value = "%" + node.Value + "%";
                    break;
                }
                QueryByFieldLike(node.MemberNode.TableName, node.MemberNode.FieldName, value);
            }
        }
Esempio n. 5
0
        void BuildSql(LikeNode node)
        {
            if (node.Method == LikeMethod.Equals)
            {
                _builder.QueryByField(node.MemberNode.TableName, node.MemberNode.FieldName,
                                      _operationDictionary[ExpressionType.Equal], node.Value);
            }
            else
            {
                string value = node.Value;
                switch (node.Method)
                {
                case LikeMethod.StartsWith:
                    value = node.Value + "%";
                    break;

                case LikeMethod.EndsWith:
                    value = "%" + node.Value;
                    break;

                case LikeMethod.Contains:
                    value = "%" + node.Value + "%";
                    break;
                }
                _builder.QueryByFieldLike(node.MemberNode.TableName, node.MemberNode.FieldName, value);
            }
        }
Esempio n. 6
0
        public void RegexSingleCharacterWildcardLiteral()
        {
            string regex = LikeNode.ConvertLikeToRegex("b[_]n");

            Assert.IsTrue(LikeNode.IsRegexMatch("b_n", regex));
            Assert.IsFalse(LikeNode.IsRegexMatch("bin", regex));
        }
        protected QueryBase VisitLike(LikeNode node, ElasticQueryMapperState state)
        {
            // TODO: Move these 3 lines to separate method for reuse?
            var fieldName = GetFormattedFieldName(node);
            var valueNode = node.GetValueNode <string>();
            var value     = ValueFormatter.FormatValueForIndexStorage(valueNode.Value, fieldName);

            // TODO: Match/MatchPhrase?

            /* Like the match query, the match_phrase query first analyzes the query string to produce a list of terms.
             * It then searches for all the terms, but keeps only documents that contain all of the search terms,
             * in the same positions relative to each other.
             */
            var query = new MatchQuery
            {
                Field = fieldName,
                Query = value.ToStringOrEmpty(),
                Boost = node.Boost,

                // TODO: Not sure if this is the best way to handle slop/similarity.
                // Use EditDistance if Slop > 0, otherwise use Ratio if MinimumSimilarity > 0 and not default, otherwise Auto
                Fuzziness = node.Slop > 0
                    ? Fuzziness.EditDistance(node.Slop)
                    : node.MinimumSimilarity > 0 && node.MinimumSimilarity != 0.5f
                        ? Fuzziness.Ratio(node.MinimumSimilarity)
                        : Fuzziness.Auto
            };

            return(query);
        }
        public void Visit(LikeNode node)
        {
            var right = Nodes.Pop();
            var left  = Nodes.Pop();

            Nodes.Push(new LikeNode(left, right));
        }
        public LikeNode Like(string value)
        {
            LikeNode likeNode = new LikeNode();

            Match(TokenType.LIKE);
            return(likeNode);
        }
Esempio n. 10
0
        public void RegexBeginsWithConversion()
        {
            string regex = LikeNode.ConvertLikeToRegex("abc%");

            Assert.IsTrue(LikeNode.IsRegexMatch("abcdef", regex));
            Assert.IsFalse(LikeNode.IsRegexMatch("123abcdef", regex));
            Assert.IsFalse(LikeNode.IsRegexMatch("123abc", regex));
        }
Esempio n. 11
0
        public void RegexPercentLiteral2()
        {
            string regex = LikeNode.ConvertLikeToRegex("%e[%]");

            Assert.IsTrue(LikeNode.IsRegexMatch("be%", regex));
            Assert.IsTrue(LikeNode.IsRegexMatch("e%", regex));
            Assert.IsFalse(LikeNode.IsRegexMatch("e%d", regex));
        }
Esempio n. 12
0
        public void RegexEndsWithConversion()
        {
            string regex = LikeNode.ConvertLikeToRegex("%def");

            Assert.IsTrue(LikeNode.IsRegexMatch("abcdef", regex));
            Assert.IsFalse(LikeNode.IsRegexMatch("abcdef123", regex));
            Assert.IsFalse(LikeNode.IsRegexMatch("def123", regex));
        }
Esempio n. 13
0
        public void RegexContains()
        {
            string regex = LikeNode.ConvertLikeToRegex("%bcd%");

            Assert.IsTrue(LikeNode.IsRegexMatch("abcdef", regex));
            Assert.IsTrue(LikeNode.IsRegexMatch("bcdef", regex));
            Assert.IsTrue(LikeNode.IsRegexMatch("abcd", regex));
            Assert.IsTrue(LikeNode.IsRegexMatch("bcd", regex));
            Assert.IsFalse(LikeNode.IsRegexMatch("def", regex));
        }
        public void Visit(LikeNode node)
        {
            Visit(new FunctionNode(nameof(Operators.Like),
                new ArgsListNode(new[] { node.Left, node.Right }),
                new string[0],
                new Traficante.TSQL.Schema.Managers.MethodInfo { FunctionMethod = typeof(Operators).GetMethod(nameof(Operators.Like)) }));

            //node.Left.Accept(this);
            //node.Right.Accept(this);
            //node.Accept(_visitor);
        }
        protected BaseQuery HandleLike(LikeNode node, ElasticSearchQueryMapperState mappingState)
        {
            var fieldName      = GetFormattedFieldName(node);
            var valueNode      = QueryHelper.GetValueNode <string>(node);
            var formattedValue = ValueFormatter.FormatValueForIndexStorage(valueNode.Value);

            var query =
                Query.Fuzzy(
                    descriptor =>
                    descriptor.OnField(fieldName)
                    .MinSimilarity(node.MinimumSimilarity)
                    .Like(formattedValue.ToStringOrEmpty())
                    .Boost(node.Boost));

            return(query);
        }
Esempio n. 16
0
        private void Build(LikeNode node)
        {
            if (node.Method == LikeMethod.Equals)
            {
                QueryFieldCondition(node.MemberNode,
                                    SqlFormatter.Operations[ExpressionType.Equal],
                                    node.Value);
            }
            else
            {
                var value        = SqlFormatter.LikeCondition(node.Value, node.Method);
                var paramId      = ContextBase.NextParamId();
                var newCondition = SqlFormatter.FieldLike(node.MemberNode, paramId);

                ContextBase.Conditions.Add(newCondition);
                ContextBase.AddParameter(paramId, value);
            }
        }
Esempio n. 17
0
        public void BuildWhere(LikeNode node)
        {
            object v  = node.Value;
            string sv = node.Value.ToString();

            switch (node.Method)
            {
            case SqlLikeType.StartsWith:
                v = sv + LikeSymbol;
                break;

            case SqlLikeType.EndsWith:
                v = LikeSymbol + sv;
                break;

            case SqlLikeType.Contains:
                v = LikeSymbol + sv + LikeSymbol;
                break;
            }
            AddCondition(node.MemberNode.TableName, node.MemberNode.FieldName, _methods[node.Method], v);
        }
        private Node ResolveQuery(MethodCallExpression callExpression)
        {
            var functionParsed = Enum.TryParse(callExpression.Method.Name, true, out LikeMethod callFunction);

            if (functionParsed)
            {
                var memberExpression = callExpression.Object as MemberExpression;
                var argumentFunction = callExpression.Arguments.First();
                var columnValue      = (string)_lambdaResolverExtension.GetExpressionValue(argumentFunction);
                var tableName        = LambdaResolverExtension.GetTableName(memberExpression);
                var columnName       = SqlBuilderFluentHelper.GetColumnName(callExpression.Object);
                var memberNode       = new MemberNode(tableName, columnName);
                var likeNode         = new LikeNode(callFunction, memberNode, columnValue);

                return(likeNode);
            }
            else
            {
                var value     = _lambdaResolverExtension.ResolveMethodCall(callExpression);
                var valueNode = new ValueNode(value);

                return(valueNode);
            }
        }
Esempio n. 19
0
        public void RegexNoWildcard()
        {
            string regex = LikeNode.ConvertLikeToRegex("bcd");

            Assert.IsFalse(LikeNode.IsRegexMatch("abcdef", regex));
        }
 public void Visit(LikeNode node)
 {
     node.Left.Accept(this);
     node.Right.Accept(this);
     node.Accept(_visitor);
 }
Esempio n. 21
0
 public void Visit(LikeNode node)
 {
 }
 protected virtual QueryNode VisitLike(LikeNode node, AzureQueryOptimizerState state)
 {
     return((QueryNode) new LikeNode(this.Visit(node.LeftNode, state), this.Visit(node.RightNode, state), node.MinimumSimilarity, node.Slop, state.Boost));
 }