Example #1
0
        public override IEnumerable <UserQueryOmniboxResult> GetResults(string rawQuery, List <OmniboxToken> tokens, string tokenPattern)
        {
            if (tokenPattern != "S" || !OmniboxParser.Manager.AllowedPermission(UserQueryPermission.ViewUserQuery))
            {
                yield break;
            }

            string ident = OmniboxUtils.CleanCommas(tokens[0].Value);

            var userQueries = autoComplete(ident, AutoCompleteLimit);

            foreach (Lite <UserQueryEntity> uq in userQueries)
            {
                var match = OmniboxUtils.Contains(uq, uq.ToString(), ident);

                yield return(new UserQueryOmniboxResult
                {
                    ToStr = ident,
                    ToStrMatch = match,
                    Distance = match !.Distance,
                    UserQuery = (Lite <UserQueryEntity>)uq,
                });
    public override IEnumerable <DashboardOmniboxResult> GetResults(string rawQuery, List <OmniboxToken> tokens, string tokenPattern)
    {
        if (tokenPattern != "S" || !OmniboxParser.Manager.AllowedPermission(DashboardPermission.ViewDashboard))
        {
            yield break;
        }

        string ident = OmniboxUtils.CleanCommas(tokens[0].Value);

        var dashboard = autoComplete(ident, AutoCompleteLimit);

        foreach (var uq in dashboard)
        {
            var match = OmniboxUtils.Contains(uq, uq.ToString() !, ident) !;

            yield return(new DashboardOmniboxResult
            {
                ToStr = ident,
                ToStrMatch = match,
                Distance = match.Distance,
                Dashboard = (Lite <DashboardEntity>)uq,
            });
        }
    }
    public override IEnumerable <EntityOmniboxResult> GetResults(string rawQuery, List <OmniboxToken> tokens, string tokenPattern)
    {
        Match m = regex.Match(tokenPattern);

        if (!m.Success)
        {
            yield break;
        }

        string ident = tokens[0].Value;

        bool isPascalCase = OmniboxUtils.IsPascalCasePattern(ident);


        var matches = OmniboxUtils.Matches(OmniboxParser.Manager.Types(), OmniboxParser.Manager.AllowedType, ident, isPascalCase);

        if (tokens.Count == 1)
        {
            yield break;
        }
        else if (tokens[1].Type == OmniboxTokenType.Number || tokens[1].Type == OmniboxTokenType.Guid)
        {
            foreach (var match in matches.OrderBy(ma => ma.Distance))
            {
                Type type = (Type)match.Value;

                if (PrimaryKey.TryParse(tokens[1].Value, type, out PrimaryKey id))
                {
                    Lite <Entity>?lite = OmniboxParser.Manager.RetrieveLite(type, id);

                    yield return(new EntityOmniboxResult
                    {
                        Type = (Type)match.Value,
                        TypeMatch = match,
                        Id = id,
                        Lite = lite,
                        Distance = match.Distance,
                    });
                }
            }
        }
        else if (tokens[1].Type == OmniboxTokenType.String)
        {
            string pattern = OmniboxUtils.CleanCommas(tokens[1].Value);

            foreach (var match in matches.OrderBy(ma => ma.Distance))
            {
                var autoComplete = OmniboxParser.Manager.Autocomplete((Type)match.Value, pattern, AutoCompleteLimit);

                if (autoComplete.Any())
                {
                    foreach (Lite <Entity> lite in autoComplete)
                    {
                        OmniboxMatch?distance = OmniboxUtils.Contains(lite, lite.ToString() ?? "", pattern);

                        if (distance != null)
                        {
                            yield return new EntityOmniboxResult
                                   {
                                       Type       = (Type)match.Value,
                                       TypeMatch  = match,
                                       ToStr      = pattern,
                                       Lite       = lite,
                                       Distance   = match.Distance + distance.Distance,
                                       ToStrMatch = distance,
                                   }
                        }
                        ;
                    }
                }
                else
                {
                    yield return(new EntityOmniboxResult
                    {
                        Type = (Type)match.Value,
                        TypeMatch = match,
                        Distance = match.Distance + 100,
                        ToStr = pattern,
                    });
                }
            }
        }
    }
    protected virtual ValueTuple[] GetValues(QueryToken queryToken, OmniboxToken omniboxToken)
    {
        if (omniboxToken.IsNull())
        {
            return new[] { new ValueTuple {
                               Value = null, Match = null
                           } }
        }
        ;

        var ft = QueryUtils.GetFilterType(queryToken.Type);

        switch (ft)
        {
        case FilterType.Integer:
        case FilterType.Decimal:
            if (omniboxToken.Type == OmniboxTokenType.Number)
            {
                if (ReflectionTools.TryParse(omniboxToken.Value, queryToken.Type, out object?result))
                {
                    return new[] { new ValueTuple {
                                       Value = result, Match = null
                                   } }
                }
                ;
            }
            break;

        case FilterType.String:
            if (omniboxToken.Type == OmniboxTokenType.String)
            {
                return new[] { new ValueTuple {
                                   Value = OmniboxUtils.CleanCommas(omniboxToken.Value), Match = null
                               } }
            }
            ;
            break;

        case FilterType.DateTime:
        case FilterType.Time:
            if (omniboxToken.Type == OmniboxTokenType.String)
            {
                var str = OmniboxUtils.CleanCommas(omniboxToken.Value);

                if (ReflectionTools.TryParse(str, queryToken.Type, out object?result))
                {
                    return new[] { new ValueTuple {
                                       Value = result, Match = null
                                   } }
                }
                ;
            }
            break;

        case FilterType.Lite:
            if (omniboxToken.Type == OmniboxTokenType.String)
            {
                var patten = OmniboxUtils.CleanCommas(omniboxToken.Value);

                var result = OmniboxParser.Manager.Autocomplete(queryToken.GetImplementations() !.Value, patten, AutoCompleteLimit);

                return(result.Select(lite => new ValueTuple {
                    Value = lite, Match = OmniboxUtils.Contains(lite, lite.ToString() !, patten)
                }).ToArray());
            }
            else if (omniboxToken.Type == OmniboxTokenType.Entity)
            {
                var error = Lite.TryParseLite(omniboxToken.Value, out Lite <Entity>?lite);
                if (string.IsNullOrEmpty(error))
                {
                    return new [] { new ValueTuple {
                                        Value = lite
                                    } }
                }
                ;
            }
            else if (omniboxToken.Type == OmniboxTokenType.Number)
            {
                var imp = queryToken.GetImplementations() !.Value;

                if (!imp.IsByAll)
                {
                    return(imp.Types.Select(t => CreateLite(t, omniboxToken.Value))
                           .NotNull().Select(t => new ValueTuple {
                        Value = t
                    }).ToArray());
                }
            }
            break;