Fix incorrect fuzzy match result for program plugin

Fix #270
This commit is contained in:
bao-qian 2015-11-11 06:20:52 +00:00
parent 1248307b96
commit a8967bab39
2 changed files with 31 additions and 27 deletions

View File

@ -30,24 +30,24 @@ namespace Wox.Plugin.Program
{
var fuzzyMather = FuzzyMatcher.Create(query.Search);
List<Program> 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<string> { 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

View File

@ -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;
}