diff --git a/Plugins/Wox.Plugin.Program/Programs.cs b/Plugins/Wox.Plugin.Program/Programs.cs index 8ec1ea9a30..347f640b8a 100644 --- a/Plugins/Wox.Plugin.Program/Programs.cs +++ b/Plugins/Wox.Plugin.Program/Programs.cs @@ -30,24 +30,24 @@ namespace Wox.Plugin.Program { var fuzzyMather = FuzzyMatcher.Create(query.Search); - List returnList = programs.Where(o => MatchProgram(o, fuzzyMather)).ToList(); - returnList.ForEach(ScoreFilter); - returnList = returnList.OrderByDescending(o => o.Score).ToList(); - - return returnList.Select(c => new Result() - { - Title = c.Title, - SubTitle = c.ExecutePath, - IcoPath = c.IcoPath, - Score = c.Score, - ContextData = c, - Action = (e) => - { - context.API.HideApp(); - context.API.ShellRun(c.ExecutePath); - return true; - } - }).ToList(); + var results = programs.Where(o => MatchProgram(o, fuzzyMather)). + Select(ScoreFilter). + OrderByDescending(o => o.Score) + .Select(c => new Result() + { + Title = c.Title, + SubTitle = c.ExecutePath, + IcoPath = c.IcoPath, + Score = c.Score, + ContextData = c, + Action = (e) => + { + context.API.HideApp(); + context.API.ShellRun(c.ExecutePath); + return true; + } + }).ToList(); + return results; } static string ResolveShortcut(string filePath) @@ -60,12 +60,10 @@ namespace Wox.Plugin.Program private bool MatchProgram(Program program, FuzzyMatcher matcher) { - if ((program.Score = matcher.Evaluate(program.Title).Score) > 0) return true; - if ((program.Score = matcher.Evaluate(program.PinyinTitle).Score) > 0) return true; - if (program.AbbrTitle != null && (program.Score = matcher.Evaluate(program.AbbrTitle).Score) > 0) return true; - if (program.ExecuteName != null && (program.Score = matcher.Evaluate(program.ExecuteName).Score) > 0) return true; - - return false; + var scores = new List { program.Title, program.PinyinTitle, program.AbbrTitle, program.ExecuteName }; + program.Score = scores.Select(s => matcher.Evaluate(s ?? string.Empty).Score).Max(); + if (program.Score > 0) return true; + else return false; } public void Init(PluginInitContext context) @@ -161,7 +159,7 @@ namespace Wox.Plugin.Program return list; } - private void ScoreFilter(Program p) + private Program ScoreFilter(Program p) { p.Score += p.Source.BonusPoints; @@ -173,6 +171,7 @@ namespace Wox.Plugin.Program if (p.Title.Contains("卸载") || p.Title.ToLower().Contains("uninstall")) p.Score -= 20; + return p; } #region ISettingProvider Members diff --git a/Wox.Plugin/Result.cs b/Wox.Plugin/Result.cs index 5352898d82..992c50a5d1 100644 --- a/Wox.Plugin/Result.cs +++ b/Wox.Plugin/Result.cs @@ -47,7 +47,10 @@ namespace Wox.Plugin Result r = obj as Result; if (r != null) { - return string.Equals(r.Title, Title) && string.Equals(r.SubTitle, SubTitle); + var equality = string.Equals(r.Title, Title) && + string.Equals(r.SubTitle, SubTitle) && + r.Score == Score; + return equality; } else { @@ -57,7 +60,9 @@ namespace Wox.Plugin public override int GetHashCode() { - var hashcode = (Title?.GetHashCode() ?? 0) ^ (SubTitle?.GetHashCode() ?? 0); + var hashcode = (Title?.GetHashCode() ?? 0) ^ + (SubTitle?.GetHashCode() ?? 0) ^ + (Score.GetHashCode()); return hashcode; }