mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 20:57:22 +02:00
Update StringMatcher's UserSettingSearchPrecision property type
makes more sense and less conversion to int for actual precision score
This commit is contained in:
@@ -12,7 +12,7 @@ namespace Wox.Infrastructure
|
|||||||
{
|
{
|
||||||
public static MatchOption DefaultMatchOption = new MatchOption();
|
public static MatchOption DefaultMatchOption = new MatchOption();
|
||||||
|
|
||||||
public static int UserSettingSearchPrecision { get; set; }
|
public static SearchPrecisionScore UserSettingSearchPrecision { get; set; }
|
||||||
|
|
||||||
public static bool ShouldUsePinyin { get; set; }
|
public static bool ShouldUsePinyin { get; set; }
|
||||||
|
|
||||||
@@ -296,7 +296,7 @@ namespace Wox.Infrastructure
|
|||||||
|
|
||||||
private bool IsSearchPrecisionScoreMet(int score)
|
private bool IsSearchPrecisionScoreMet(int score)
|
||||||
{
|
{
|
||||||
return score >= UserSettingSearchPrecision;
|
return score >= (int)UserSettingSearchPrecision;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int ApplySearchPrecisionFilter(int score)
|
private int ApplySearchPrecisionFilter(int score)
|
||||||
|
|||||||
@@ -45,16 +45,19 @@ namespace Wox.Infrastructure.UserSettings
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var precisionScore = (StringMatcher.SearchPrecisionScore)Enum.Parse(
|
var precisionScore = (StringMatcher.SearchPrecisionScore)Enum
|
||||||
typeof(StringMatcher.SearchPrecisionScore),
|
.Parse(typeof(StringMatcher.SearchPrecisionScore), value);
|
||||||
value);
|
|
||||||
QuerySearchPrecision = precisionScore;
|
QuerySearchPrecision = precisionScore;
|
||||||
StringMatcher.UserSettingSearchPrecision = (int)precisionScore;
|
StringMatcher.UserSettingSearchPrecision = precisionScore;
|
||||||
}
|
}
|
||||||
catch (System.Exception e)
|
catch (ArgumentException e)
|
||||||
{
|
{
|
||||||
// what do we do here?!
|
Logger.Log.Exception(nameof(Settings), "Failed to load QuerySearchPrecisionString value from Settings file", e);
|
||||||
Logger.Log.Exception(nameof(Settings), "Fail to set QuerySearchPrecision", e);
|
|
||||||
|
QuerySearchPrecision = StringMatcher.SearchPrecisionScore.Regular;
|
||||||
|
StringMatcher.UserSettingSearchPrecision = StringMatcher.SearchPrecisionScore.Regular;
|
||||||
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ using System.Diagnostics;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Wox.Infrastructure;
|
using Wox.Infrastructure;
|
||||||
using Wox.Infrastructure.UserSettings;
|
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
|
|
||||||
namespace Wox.Test
|
namespace Wox.Test
|
||||||
@@ -138,20 +137,20 @@ namespace Wox.Test
|
|||||||
Assert.AreEqual(expectedScore, rawScore, $"Expected score for compare string '{compareString}': {expectedScore}, Actual: {rawScore}");
|
Assert.AreEqual(expectedScore, rawScore, $"Expected score for compare string '{compareString}': {expectedScore}, Actual: {rawScore}");
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestCase("goo", "Google Chrome", (int)StringMatcher.SearchPrecisionScore.Regular, true)]
|
[TestCase("goo", "Google Chrome", StringMatcher.SearchPrecisionScore.Regular, true)]
|
||||||
[TestCase("chr", "Google Chrome", (int)StringMatcher.SearchPrecisionScore.Low, true)]
|
[TestCase("chr", "Google Chrome", StringMatcher.SearchPrecisionScore.Low, true)]
|
||||||
[TestCase("chr", "Chrome", (int)StringMatcher.SearchPrecisionScore.Regular, true)]
|
[TestCase("chr", "Chrome", StringMatcher.SearchPrecisionScore.Regular, true)]
|
||||||
[TestCase("chr", "Help cure hope raise on mind entity Chrome", (int)StringMatcher.SearchPrecisionScore.Regular, false)]
|
[TestCase("chr", "Help cure hope raise on mind entity Chrome", StringMatcher.SearchPrecisionScore.Regular, false)]
|
||||||
[TestCase("chr", "Help cure hope raise on mind entity Chrome", (int)StringMatcher.SearchPrecisionScore.Low, true)]
|
[TestCase("chr", "Help cure hope raise on mind entity Chrome", StringMatcher.SearchPrecisionScore.Low, true)]
|
||||||
[TestCase("chr", "Candy Crush Saga from King", (int)StringMatcher.SearchPrecisionScore.Regular, false)]
|
[TestCase("chr", "Candy Crush Saga from King", StringMatcher.SearchPrecisionScore.Regular, false)]
|
||||||
[TestCase("chr", "Candy Crush Saga from King", (int)StringMatcher.SearchPrecisionScore.None, true)]
|
[TestCase("chr", "Candy Crush Saga from King", StringMatcher.SearchPrecisionScore.None, true)]
|
||||||
[TestCase("ccs", "Candy Crush Saga from King", (int)StringMatcher.SearchPrecisionScore.Low, true)]
|
[TestCase("ccs", "Candy Crush Saga from King", StringMatcher.SearchPrecisionScore.Low, true)]
|
||||||
[TestCase("cand", "Candy Crush Saga from King", (int)StringMatcher.SearchPrecisionScore.Regular, true)]
|
[TestCase("cand", "Candy Crush Saga from King",StringMatcher.SearchPrecisionScore.Regular, true)]
|
||||||
[TestCase("cand", "Help cure hope raise on mind entity Chrome", (int)StringMatcher.SearchPrecisionScore.Regular, false)]
|
[TestCase("cand", "Help cure hope raise on mind entity Chrome", StringMatcher.SearchPrecisionScore.Regular, false)]
|
||||||
public void WhenGivenDesiredPrecisionThenShouldReturnAllResultsGreaterOrEqual(
|
public void WhenGivenDesiredPrecisionThenShouldReturnAllResultsGreaterOrEqual(
|
||||||
string queryString,
|
string queryString,
|
||||||
string compareString,
|
string compareString,
|
||||||
int expectedPrecisionScore,
|
StringMatcher.SearchPrecisionScore expectedPrecisionScore,
|
||||||
bool expectedPrecisionResult)
|
bool expectedPrecisionResult)
|
||||||
{
|
{
|
||||||
// When
|
// When
|
||||||
@@ -163,7 +162,7 @@ namespace Wox.Test
|
|||||||
Debug.WriteLine("");
|
Debug.WriteLine("");
|
||||||
Debug.WriteLine("###############################################");
|
Debug.WriteLine("###############################################");
|
||||||
Debug.WriteLine($"QueryString: {queryString} CompareString: {compareString}");
|
Debug.WriteLine($"QueryString: {queryString} CompareString: {compareString}");
|
||||||
Debug.WriteLine($"RAW SCORE: {matchResult.RawScore.ToString()}, PrecisionLevelSetAt: {(StringMatcher.SearchPrecisionScore)expectedPrecisionScore} ({expectedPrecisionScore})");
|
Debug.WriteLine($"RAW SCORE: {matchResult.RawScore.ToString()}, PrecisionLevelSetAt: {expectedPrecisionScore} ({(int)expectedPrecisionScore})");
|
||||||
Debug.WriteLine("###############################################");
|
Debug.WriteLine("###############################################");
|
||||||
Debug.WriteLine("");
|
Debug.WriteLine("");
|
||||||
|
|
||||||
@@ -172,27 +171,27 @@ namespace Wox.Test
|
|||||||
$"Query:{queryString}{Environment.NewLine} " +
|
$"Query:{queryString}{Environment.NewLine} " +
|
||||||
$"Compare:{compareString}{Environment.NewLine}" +
|
$"Compare:{compareString}{Environment.NewLine}" +
|
||||||
$"Raw Score: {matchResult.RawScore}{Environment.NewLine}" +
|
$"Raw Score: {matchResult.RawScore}{Environment.NewLine}" +
|
||||||
$"Precision Level: {(StringMatcher.SearchPrecisionScore)expectedPrecisionScore}={expectedPrecisionScore}");
|
$"Precision Score: {(int)expectedPrecisionScore}");
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestCase("exce", "OverLeaf-Latex: An online LaTeX editor", (int)StringMatcher.SearchPrecisionScore.Regular, false)]
|
[TestCase("exce", "OverLeaf-Latex: An online LaTeX editor", StringMatcher.SearchPrecisionScore.Regular, false)]
|
||||||
[TestCase("term", "Windows Terminal (Preview)", (int)StringMatcher.SearchPrecisionScore.Regular, true)]
|
[TestCase("term", "Windows Terminal (Preview)", StringMatcher.SearchPrecisionScore.Regular, true)]
|
||||||
[TestCase("sql s managa", MicrosoftSqlServerManagementStudio, (int)StringMatcher.SearchPrecisionScore.Regular, false)]
|
[TestCase("sql s managa", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, false)]
|
||||||
[TestCase("sql' s manag", MicrosoftSqlServerManagementStudio, (int)StringMatcher.SearchPrecisionScore.Regular, false)]
|
[TestCase("sql' s manag", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, false)]
|
||||||
[TestCase("sql s manag", MicrosoftSqlServerManagementStudio, (int)StringMatcher.SearchPrecisionScore.Regular, true)]
|
[TestCase("sql s manag", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
|
||||||
[TestCase("sql manag", MicrosoftSqlServerManagementStudio, (int)StringMatcher.SearchPrecisionScore.Regular, true)]
|
[TestCase("sql manag", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
|
||||||
[TestCase("sql", MicrosoftSqlServerManagementStudio, (int)StringMatcher.SearchPrecisionScore.Regular, true)]
|
[TestCase("sql", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
|
||||||
[TestCase("sql serv", MicrosoftSqlServerManagementStudio, (int)StringMatcher.SearchPrecisionScore.Regular, true)]
|
[TestCase("sql serv", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
|
||||||
[TestCase("sql studio", MicrosoftSqlServerManagementStudio, (int)StringMatcher.SearchPrecisionScore.Regular, true)]
|
[TestCase("sql studio", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
|
||||||
[TestCase("mic", MicrosoftSqlServerManagementStudio, (int)StringMatcher.SearchPrecisionScore.Regular, true)]
|
[TestCase("mic", MicrosoftSqlServerManagementStudio, StringMatcher.SearchPrecisionScore.Regular, true)]
|
||||||
[TestCase("chr", "Shutdown", (int)StringMatcher.SearchPrecisionScore.Regular, false)]
|
[TestCase("chr", "Shutdown", StringMatcher.SearchPrecisionScore.Regular, false)]
|
||||||
[TestCase("chr", "Change settings for text-to-speech and for speech recognition (if installed).", (int)StringMatcher.SearchPrecisionScore.Regular, false)]
|
[TestCase("chr", "Change settings for text-to-speech and for speech recognition (if installed).", StringMatcher.SearchPrecisionScore.Regular, false)]
|
||||||
[TestCase("a test", "This is a test", (int)StringMatcher.SearchPrecisionScore.Regular, true)]
|
[TestCase("a test", "This is a test", StringMatcher.SearchPrecisionScore.Regular, true)]
|
||||||
[TestCase("test", "This is a test", (int)StringMatcher.SearchPrecisionScore.Regular, true)]
|
[TestCase("test", "This is a test", StringMatcher.SearchPrecisionScore.Regular, true)]
|
||||||
public void WhenGivenQueryShouldReturnResultsContainingAllQuerySubstrings(
|
public void WhenGivenQueryShouldReturnResultsContainingAllQuerySubstrings(
|
||||||
string queryString,
|
string queryString,
|
||||||
string compareString,
|
string compareString,
|
||||||
int expectedPrecisionScore,
|
StringMatcher.SearchPrecisionScore expectedPrecisionScore,
|
||||||
bool expectedPrecisionResult)
|
bool expectedPrecisionResult)
|
||||||
{
|
{
|
||||||
// When
|
// When
|
||||||
@@ -204,7 +203,7 @@ namespace Wox.Test
|
|||||||
Debug.WriteLine("");
|
Debug.WriteLine("");
|
||||||
Debug.WriteLine("###############################################");
|
Debug.WriteLine("###############################################");
|
||||||
Debug.WriteLine($"QueryString: {queryString} CompareString: {compareString}");
|
Debug.WriteLine($"QueryString: {queryString} CompareString: {compareString}");
|
||||||
Debug.WriteLine($"RAW SCORE: {matchResult.RawScore.ToString()}, PrecisionLevelSetAt: {(StringMatcher.SearchPrecisionScore)expectedPrecisionScore} ({expectedPrecisionScore})");
|
Debug.WriteLine($"RAW SCORE: {matchResult.RawScore.ToString()}, PrecisionLevelSetAt: {expectedPrecisionScore} ({(int)expectedPrecisionScore})");
|
||||||
Debug.WriteLine("###############################################");
|
Debug.WriteLine("###############################################");
|
||||||
Debug.WriteLine("");
|
Debug.WriteLine("");
|
||||||
|
|
||||||
@@ -213,7 +212,7 @@ namespace Wox.Test
|
|||||||
$"Query:{queryString}{Environment.NewLine} " +
|
$"Query:{queryString}{Environment.NewLine} " +
|
||||||
$"Compare:{compareString}{Environment.NewLine}" +
|
$"Compare:{compareString}{Environment.NewLine}" +
|
||||||
$"Raw Score: {matchResult.RawScore}{Environment.NewLine}" +
|
$"Raw Score: {matchResult.RawScore}{Environment.NewLine}" +
|
||||||
$"Precision Level: {(StringMatcher.SearchPrecisionScore)expectedPrecisionScore}={expectedPrecisionScore}");
|
$"Precision Score: {(int)expectedPrecisionScore}");
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestCase("sql servman", MicrosoftSqlServerManagementStudio, false)]
|
[TestCase("sql servman", MicrosoftSqlServerManagementStudio, false)]
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ namespace Wox
|
|||||||
|
|
||||||
Alphabet.Initialize(_settings);
|
Alphabet.Initialize(_settings);
|
||||||
|
|
||||||
StringMatcher.UserSettingSearchPrecision = (int)_settings.QuerySearchPrecision;
|
StringMatcher.UserSettingSearchPrecision = _settings.QuerySearchPrecision;
|
||||||
StringMatcher.ShouldUsePinyin = _settings.ShouldUsePinyin;
|
StringMatcher.ShouldUsePinyin = _settings.ShouldUsePinyin;
|
||||||
|
|
||||||
PluginManager.LoadPlugins(_settings.PluginSettings);
|
PluginManager.LoadPlugins(_settings.PluginSettings);
|
||||||
|
|||||||
Reference in New Issue
Block a user