Beispiel #1
0
 internal SearchExpression(SearchExpressionType types,
                           StringView outerText, StringView innerText, StringView alias,
                           SearchExpressionEvaluator evaluator, SearchExpression[] parameters)
 {
     this.types      = types;
     this.outerText  = outerText;
     this.innerText  = innerText.valid ? innerText : outerText;
     this.alias      = alias;
     this.parameters = parameters ?? new SearchExpression[0];
     this.evaluator  = evaluator;
 }
        public static void ValidateExpressionArguments(SearchExpressionEvaluator evaluator, SearchExpression[] args, IEnumerable <Signature> signatures, StringView expressionInnerText)
        {
            // First pass to get all valid argument number signatures (must do a ToList to separate the 2 passes)
            // Second pass to validate the argument types. The last error is kept (lowest number of arguments if no signature matches the number of argument, wrong type if there is at least one)
            var lastError     = "";
            var errorPosition = StringView.Null;

            if (signatures.Where(s => ValidateExpressionArgumentsCount(evaluator.name, args, s, (msg, errorPos) => { lastError = msg; errorPosition = errorPos; })).ToList()
                .Any(s => ValidateExpressionArguments(evaluator.name, args, s, (msg, errorPos) => { lastError = msg; errorPosition = errorPos; })))
            {
                return;
            }

            if (!errorPosition.valid)
            {
                errorPosition = expressionInnerText;
            }
            throw new SearchExpressionParseException($"Syntax error: {lastError}", errorPosition.startIndex, errorPosition.Length);
        }
Beispiel #3
0
        public static IEnumerable <SearchItem> GroupBy(SearchExpressionContext c)
        {
            string selector = null;

            if (c.args.Length > 1)
            {
                selector = c.args[1].innerText.ToString();
            }

            var outputValueFieldName = System.Guid.NewGuid().ToString("N");
            var dataSet = SelectorManager.SelectValues(c.search, c.args[0].Execute(c), selector, outputValueFieldName);

            foreach (var _group in dataSet.GroupBy(item => item.GetValue(outputValueFieldName)))
            {
                var group   = _group;
                var groupId = group.Key?.ToString() ?? $"group{++s_NextGroupId}";

                if (c.HasFlag(SearchExpressionExecutionFlags.Expand))
                {
                    var evaluator = new SearchExpressionEvaluator(groupId, _ => group, SearchExpressionEvaluationHints.Default);
                    var genExpr   = new SearchExpression(SearchExpressionType.Group,
                                                         groupId.GetStringView(), groupId.GetStringView(), (group.Key?.ToString() ?? groupId).GetStringView(),
                                                         evaluator);

                    yield return(EvaluatorUtils.CreateSearchExpressionItem(genExpr));
                }
                else
                {
                    SearchProvider groupProvider = null;
                    foreach (var item in group)
                    {
                        if (groupProvider == null)
                        {
                            groupProvider = SearchUtils.CreateGroupProvider(item.provider, groupId, s_NextGroupId);
                        }
                        item.provider = groupProvider;
                        yield return(item);
                    }
                }
            }
        }
Beispiel #4
0
 internal SearchExpression(SearchExpressionType types, StringView text, SearchExpressionEvaluator evaluator, SearchExpression[] parameters)
     : this(types, text, text, StringView.nil, evaluator, parameters)
 {
 }
Beispiel #5
0
 internal SearchExpression(SearchExpressionType types, StringView text, SearchExpressionEvaluator evaluator)
     : this(types, text, text, StringView.nil, evaluator, null)
 {
 }
Beispiel #6
0
 internal SearchExpression(SearchExpressionType types, StringView outerText, StringView innerText, StringView alias, SearchExpressionEvaluator evaluator)
     : this(types, outerText, innerText, alias, evaluator, null)
 {
 }
 public SearchExpression(SearchExpressionType types, StringView text, SearchExpressionEvaluator evaluator)
     : this(types, text, text, StringView.Null, evaluator, null)
 {
 }
 public SearchExpression(SearchExpressionType types, StringView outerText, StringView innerText, SearchExpressionEvaluator evaluator, SearchExpression[] parameters)
     : this(types, outerText, innerText, StringView.Null, evaluator, parameters)
 {
 }
 public SearchExpression(SearchExpressionType types, StringView outerText, StringView innerText, SearchExpressionEvaluator evaluator)
     : this(types, outerText, innerText, StringView.Null, evaluator, null)
 {
 }