public override IEnumerable <HelpModuleOmniboxResult> GetResults(string rawQuery, List <OmniboxToken> tokens, string tokenPattern) { if (!OmniboxParser.Manager.AllowedPermission(HelpPermissions.ViewHelp)) { yield break; } if (tokens.Count == 0 || !regex.IsMatch(tokenPattern)) { yield break; } string key = tokens[0].Value; var keyMatch = OmniboxUtils.Contains(NiceName(), NiceName(), key) ?? OmniboxUtils.Contains("help", "help", key); if (keyMatch == null) { yield break; } if (tokenPattern == "I" && rawQuery.EndsWith(" ")) { yield return(new HelpModuleOmniboxResult { Distance = keyMatch.Distance, KeywordMatch = keyMatch, SecondMatch = null }); yield break; } if (tokens.Count != 2) { yield break; } if (tokens[1].Type == OmniboxTokenType.String) { yield return(new HelpModuleOmniboxResult { Distance = keyMatch.Distance, KeywordMatch = keyMatch, SearchString = tokens[1].Value.Trim('\'', '"') }); yield break; } string pattern = tokens[1].Value; bool isPascalCase = OmniboxUtils.IsPascalCasePattern(pattern); foreach (var match in OmniboxUtils.Matches(OmniboxParser.Manager.Types(), OmniboxParser.Manager.AllowedType, pattern, isPascalCase).OrderBy(ma => ma.Distance)) { var type = (Type)match.Value; if (OmniboxParser.Manager.AllowedQuery(type)) { yield return(new HelpModuleOmniboxResult { Distance = keyMatch.Distance + match.Distance, KeywordMatch = keyMatch, Type = type, SecondMatch = match }); } } }
public override IEnumerable <ChartOmniboxResult> GetResults(string rawQuery, List <OmniboxToken> tokens, string tokenPattern) { if (!OmniboxParser.Manager.AllowedPermission(ChartPermission.ViewCharting)) { yield break; } Match m = regex.Match(tokenPattern); if (!m.Success) { yield break; } string key = tokens[0].Value; var keyMatch = OmniboxUtils.Contains(NiceName(), NiceName(), key); if (keyMatch == null) { yield break; } if (tokens.Count == 1) { yield return new ChartOmniboxResult { Distance = keyMatch.Distance, KeywordMatch = keyMatch } } ; else { string pattern = tokens[1].Value; bool isPascalCase = OmniboxUtils.IsPascalCasePattern(pattern); foreach (var match in OmniboxUtils.Matches(OmniboxParser.Manager.GetQueries(), OmniboxParser.Manager.AllowedQuery, pattern, isPascalCase).OrderBy(ma => ma.Distance)) { yield return(new ChartOmniboxResult { Distance = keyMatch.Distance + match.Distance, KeywordMatch = keyMatch, QueryName = match.Value, QueryNameMatch = match }); } } }
public override IEnumerable <MapOmniboxResult> GetResults(string rawQuery, List <OmniboxToken> tokens, string tokenPattern) { if (!OmniboxParser.Manager.AllowedPermission(MapPermission.ViewMap)) { yield break; } Match m = regex.Match(tokenPattern); if (!m.Success) { yield break; } string key = tokens[0].Value; var keyMatch = OmniboxUtils.Contains(NiceName(), NiceName(), key); if (keyMatch == null) { yield break; } if (tokens.Count == 1) { yield return new MapOmniboxResult { Distance = keyMatch.Distance, KeywordMatch = keyMatch } } ; else { string pattern = tokens[1].Value; bool isPascalCase = OmniboxUtils.IsPascalCasePattern(pattern); var types = OmniboxParser.Manager.Types().Where(a => HasOperations(a.Value)).ToDictionary(); foreach (var match in OmniboxUtils.Matches(types, OmniboxParser.Manager.AllowedType, pattern, isPascalCase).OrderBy(ma => ma.Distance)) { var type = match.Value; yield return(new MapOmniboxResult { Distance = keyMatch.Distance + match.Distance, KeywordMatch = keyMatch, Type = (Type)type, TypeMatch = match }); } } }
public override IEnumerable <SpecialOmniboxResult> GetResults(string rawQuery, List <OmniboxToken> tokens, string tokenPattern) { if (!regex.IsMatch(tokenPattern)) { return(Enumerable.Empty <SpecialOmniboxResult>()); } string ident = tokens.Count == 1 ? "" : tokens[1].Value; bool isPascalCase = OmniboxUtils.IsPascalCasePattern(ident); return(OmniboxUtils.Matches(Actions, a => a.Allowed(), ident, isPascalCase) .Select(m => new SpecialOmniboxResult { Match = m, Distance = m.Distance })); }
public override IEnumerable <TreeOmniboxResult> GetResults(string rawQuery, List <OmniboxToken> tokens, string tokenPattern) { if (tokenPattern != "I") { yield break; } string pattern = tokens[0].Value; bool isPascalCase = OmniboxUtils.IsPascalCasePattern(pattern); foreach (var match in OmniboxUtils.Matches(OmniboxParser.Manager.Types(), t => typeof(TreeEntity).IsAssignableFrom(t) && OmniboxParser.Manager.AllowedType(t), pattern, isPascalCase).OrderBy(ma => ma.Distance)) { var type = match.Value; yield return(new TreeOmniboxResult { Distance = match.Distance - 0.1f, Type = (Type)match.Value, TypeMatch = match }); } }
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, }); } } } }
public override IEnumerable <DynamicQueryOmniboxResult> GetResults(string rawQuery, List <OmniboxToken> tokens, string tokenPattern) { Match m = regex.Match(tokenPattern); if (!m.Success) { yield break; } string pattern = tokens[0].Value; bool isPascalCase = OmniboxUtils.IsPascalCasePattern(pattern); List <FilterSyntax>?syntaxSequence = null; foreach (var match in OmniboxUtils.Matches(OmniboxParser.Manager.GetQueries(), OmniboxParser.Manager.AllowedQuery, pattern, isPascalCase).OrderBy(ma => ma.Distance)) { var queryName = match.Value; if (syntaxSequence == null) { syntaxSequence = SyntaxSequence(m); } if (syntaxSequence.Any()) { QueryDescription description = OmniboxParser.Manager.GetDescription(match.Value); IEnumerable <IEnumerable <OmniboxFilterResult> > bruteFilters = syntaxSequence.Select(a => GetFilterQueries(rawQuery, description, a, tokens)); foreach (var list in bruteFilters.CartesianProduct()) { yield return(new DynamicQueryOmniboxResult { QueryName = match.Value, QueryNameMatch = match, Distance = match.Distance + list.Average(a => a.Distance), Filters = list.ToList(), }); } } else { if (match.Text == pattern && tokens.Count == 1 && tokens[0].Next(rawQuery) == ' ') { QueryDescription description = OmniboxParser.Manager.GetDescription(match.Value); foreach (var qt in QueryUtils.SubTokens(null, description, SubTokensOptions.CanAnyAll | SubTokensOptions.CanElement)) { yield return(new DynamicQueryOmniboxResult { QueryName = match.Value, QueryNameMatch = match, Distance = match.Distance, Filters = new List <OmniboxFilterResult> { new OmniboxFilterResult(0, null, qt, null) }, }); } } else { yield return(new DynamicQueryOmniboxResult { QueryName = match.Value, QueryNameMatch = match, Distance = match.Distance, Filters = new List <OmniboxFilterResult>() }); } } } }