Ejemplo n.º 1
0
        private void QuerySuggestions(string keyword, Query query, string subtitle, WebSearch webSearch)
        {
            ISuggestionSource sugg = SuggestionSourceFactory.GetSuggestionSource(WebSearchStorage.Instance.WebSearchSuggestionSource, context);

            if (sugg != null)
            {
                var result = sugg.GetSuggestions(keyword);
                if (result != null)
                {
                    context.API.PushResults(query, context.CurrentPluginMetadata,
                                            result.Select(o => new Result()
                    {
                        Title    = o,
                        SubTitle = subtitle,
                        Score    = 5,
                        IcoPath  = webSearch.IconPath,
                        Action   = (c) =>
                        {
                            Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(o)));
                            return(true);
                        }
                    }).ToList());
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Suggester"/> class.
        /// </summary>
        /// <param name="suggestionSources">The suggestion sources.</param>
        public Suggester(ISuggestionSource[] suggestionSources)
        {
            if (suggestionSources == null)
            {
                throw new ArgumentNullException();
            }

            this.sources = suggestionSources;
        }
Ejemplo n.º 3
0
        private IEnumerable <Result> ResultsFromSuggestions(string keyword, string subtitle, WebSearch webSearch)
        {
            ISuggestionSource sugg = SuggestionSourceFactory.GetSuggestionSource(_settings.WebSearchSuggestionSource, Context);
            var suggestions        = sugg?.GetSuggestions(keyword);

            if (suggestions != null)
            {
                var resultsFromSuggestion = suggestions.Select(o => new Result
                {
                    Title    = o,
                    SubTitle = subtitle,
                    Score    = 5,
                    IcoPath  = webSearch.IconPath,
                    Action   = c =>
                    {
                        Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(o)));
                        return(true);
                    }
                });
                return(resultsFromSuggestion);
            }
            return(new List <Result>());
        }
Ejemplo n.º 4
0
 public static OptionBuilder <T> AddSuggestions <T>(this OptionBuilder <T> builder, ISuggestionSource suggestionSource)
 {
     (builder ?? throw Exceptions.BuildArgumentNull(nameof(builder)))
     .Suggestions.Add(suggestionSource ?? throw Exceptions.BuildArgumentNull(nameof(suggestionSource)));
     return(builder);
 }
Ejemplo n.º 5
0
        protected override List <Result> QueryInternal(Query query)
        {
            List <Result> results = new List <Result>();

            WebSearch webSearch =
                UserSettingStorage.Instance.WebSearches.FirstOrDefault(o => o.ActionWord == query.ActionName && o.Enabled);

            if (webSearch != null)
            {
                string keyword  = query.ActionParameters.Count > 0 ? query.GetAllRemainingParameter() : "";
                string title    = keyword;
                string subtitle = "Search " + webSearch.Title;
                if (string.IsNullOrEmpty(keyword))
                {
                    title    = subtitle;
                    subtitle = null;
                }
                context.API.PushResults(query, context.CurrentPluginMetadata, new List <Result>()
                {
                    new Result()
                    {
                        Title    = title,
                        SubTitle = subtitle,
                        Score    = 6,
                        IcoPath  = webSearch.IconPath,
                        Action   = (c) =>
                        {
                            Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(keyword)));
                            return(true);
                        }
                    }
                });

                if (UserSettingStorage.Instance.EnableWebSearchSuggestion && !string.IsNullOrEmpty(keyword))
                {
                    ISuggestionSource sugg = SuggestionSourceFactory.GetSuggestionSource(
                        UserSettingStorage.Instance.WebSearchSuggestionSource);
                    if (sugg != null)
                    {
                        var result = sugg.GetSuggestions(keyword);
                        if (result != null)
                        {
                            context.API.PushResults(query, context.CurrentPluginMetadata,
                                                    result.Select(o => new Result()
                            {
                                Title    = o,
                                SubTitle = subtitle,
                                Score    = 5,
                                IcoPath  = webSearch.IconPath,
                                Action   = (c) =>
                                {
                                    Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(o)));
                                    return(true);
                                }
                            }).ToList());
                        }
                    }
                }
            }

            return(results);
        }