mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 12:18:50 +02:00
Update Program plugin with new code
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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))
|
||||||
|
|||||||
Reference in New Issue
Block a user