Update Program plugin with new code

This commit is contained in:
Jeremy Wu
2019-09-29 15:03:30 +10:00
parent acd42f9cc6
commit cc23495591
3 changed files with 21 additions and 10 deletions

View File

@@ -240,9 +240,9 @@ namespace Wox.Plugin.Program.Programs
private int Score(string query) private int Score(string query)
{ {
var score1 = StringMatcher.Score(DisplayName, query); var score1 = StringMatcher.FuzzySearch(query, DisplayName).ScoreAfterSearchPrecisionFilter();
var score2 = StringMatcher.ScoreForPinyin(DisplayName, query); var score2 = StringMatcher.ScoreForPinyin(DisplayName, query);
var score3 = StringMatcher.Score(Description, query); var score3 = StringMatcher.FuzzySearch(query, Description).ScoreAfterSearchPrecisionFilter();
var score4 = StringMatcher.ScoreForPinyin(Description, query); var score4 = StringMatcher.ScoreForPinyin(Description, query);
var score = new[] { score1, score2, score3, score4 }.Max(); var score = new[] { score1, score2, score3, score4 }.Max();
return score; return score;

View File

@@ -31,11 +31,11 @@ namespace Wox.Plugin.Program.Programs
private int Score(string query) private int Score(string query)
{ {
var score1 = StringMatcher.Score(Name, query); var score1 = StringMatcher.FuzzySearch(query, Name).ScoreAfterSearchPrecisionFilter();
var score2 = StringMatcher.ScoreForPinyin(Name, query); var score2 = StringMatcher.ScoreForPinyin(Name, query);
var score3 = StringMatcher.Score(Description, query); var score3 = StringMatcher.FuzzySearch(query, Description).ScoreAfterSearchPrecisionFilter();
var score4 = StringMatcher.ScoreForPinyin(Description, query); var score4 = StringMatcher.ScoreForPinyin(Description, query);
var score5 = StringMatcher.Score(ExecutableName, query); var score5 = StringMatcher.FuzzySearch(query, ExecutableName).ScoreAfterSearchPrecisionFilter();
var score = new[] { score1, score2, score3, score4, score5 }.Max(); var score = new[] { score1, score2, score3, score4, score5 }.Max();
return score; return score;
} }

View File

@@ -1,4 +1,4 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Wox.Infrastructure.Logger; using Wox.Infrastructure.Logger;
@@ -29,11 +29,9 @@ namespace Wox.Infrastructure
return FuzzySearch(target, source, new MatchOption()).Score > 0; return FuzzySearch(target, source, new MatchOption()).Score > 0;
} }
public enum SearchPrecisionScore public static MatchResult FuzzySearch(string query, string stringToCompare)
{ {
Regular = 50, return FuzzySearch(query, stringToCompare, new MatchOption());
Low = 20,
None = 0
} }
/// <summary> /// <summary>
@@ -107,6 +105,13 @@ namespace Wox.Infrastructure
return score; return score;
} }
public enum SearchPrecisionScore
{
Regular = 50,
Low = 20,
None = 0
}
public static bool IsSearchPrecisionScoreMet(this MatchResult matchResult) public static bool IsSearchPrecisionScoreMet(this MatchResult matchResult)
{ {
var precisionScore = (SearchPrecisionScore)Enum.Parse(typeof(SearchPrecisionScore), var precisionScore = (SearchPrecisionScore)Enum.Parse(typeof(SearchPrecisionScore),
@@ -114,6 +119,12 @@ namespace Wox.Infrastructure
return matchResult.Score >= (int)precisionScore; return matchResult.Score >= (int)precisionScore;
} }
public static int ScoreAfterSearchPrecisionFilter(this MatchResult matchResult)
{
return matchResult.IsSearchPrecisionScoreMet() ? matchResult.Score : 0;
}
public static int ScoreForPinyin(string source, string target) public static int ScoreForPinyin(string source, string target)
{ {
if (!string.IsNullOrEmpty(source) && !string.IsNullOrEmpty(target)) if (!string.IsNullOrEmpty(source) && !string.IsNullOrEmpty(target))