Add Google suggestions for web searches

Fix issues with push results
This commit is contained in:
Yeechan Lu
2014-03-27 16:56:50 +08:00
parent c8fcfcd28c
commit 9a2ffc1d7c
10 changed files with 249 additions and 18 deletions

View File

@@ -7,11 +7,14 @@ using Newtonsoft.Json;
using Wox.Infrastructure;
using Wox.Infrastructure.Storage;
using Wox.Infrastructure.Storage.UserSettings;
using Wox.Plugin.System.SuggestionSources;
namespace Wox.Plugin.System
{
public class WebSearchPlugin : BaseSystemPlugin
{
private PluginInitContext context;
protected override List<Result> QueryInternal(Query query)
{
List<Result> results = new List<Result>();
@@ -23,22 +26,49 @@ namespace Wox.Plugin.System
if (webSearch != null)
{
string keyword = query.ActionParameters.Count > 0 ? query.GetAllRemainingParameter() : "";
string title = string.Format("Search {0} for \"{1}\"", webSearch.Title, keyword);
string title = keyword;
string subtitle = "Search " + webSearch.Title;
if (string.IsNullOrEmpty(keyword))
{
title = "Search " + webSearch.Title;
title = subtitle;
subtitle = null;
}
results.Add(new Result()
context.PushResults(query, new List<Result>()
{
Title = title,
Score = 6,
IcoPath = webSearch.IconPath,
Action = (c) =>
new Result()
{
Process.Start(webSearch.Url.Replace("{q}", keyword));
return true;
Title = title,
SubTitle = subtitle,
Score = 6,
IcoPath = webSearch.IconPath,
Action = (c) =>
{
Process.Start(webSearch.Url.Replace("{q}", keyword));
return true;
}
}
});
if (!string.IsNullOrEmpty(keyword))
{
ISuggestionSource sugg = new Google();
var result = sugg.GetSuggestions(keyword);
if (result != null)
{
context.PushResults(query, result.Select(o => new Result()
{
Title = o,
SubTitle = subtitle,
Score = 5,
IcoPath = webSearch.IconPath,
Action = (c) =>
{
Process.Start(webSearch.Url.Replace("{q}", o));
return true;
}
}).ToList());
}
}
}
return results;
@@ -46,6 +76,7 @@ namespace Wox.Plugin.System
protected override void InitInternal(PluginInitContext context)
{
this.context = context;
}
}
}