From 6ebca7fa7cf0462d9ff9734f216d7ef460fef16d Mon Sep 17 00:00:00 2001 From: SysC0mp Date: Tue, 3 Dec 2019 14:58:52 +0100 Subject: [PATCH] Apply search precision filter on assignment The search precision must be used, so it makes sense to apply the filter directly on score assignment. Score will be "0" if precision filter was not met. --- Wox.Infrastructure/StringMatcher.cs | 49 +++++++++++++++++++---------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/Wox.Infrastructure/StringMatcher.cs b/Wox.Infrastructure/StringMatcher.cs index 8d66e19c21..d24bdf2c35 100644 --- a/Wox.Infrastructure/StringMatcher.cs +++ b/Wox.Infrastructure/StringMatcher.cs @@ -120,19 +120,6 @@ namespace Wox.Infrastructure None = 0 } - public static bool IsSearchPrecisionScoreMet(this MatchResult matchResult) - { - var precisionScore = (SearchPrecisionScore)Enum.Parse(typeof(SearchPrecisionScore), - UserSettingSearchPrecision ?? SearchPrecisionScore.Regular.ToString()); - 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) { if (!string.IsNullOrEmpty(source) && !string.IsNullOrEmpty(target)) @@ -164,12 +151,42 @@ namespace Wox.Infrastructure public class MatchResult { public bool Success { get; set; } - public int Score { get; set; } + + private int _score; + public int Score + { + get + { + return _score; + } + set + { + _score = ApplySearchPrecisionFilter(value); + } + } /// - /// highlight string + /// Matched data to highlight. /// - public string Value { get; set; } + public List MatchData { get; set; } + + public bool IsSearchPrecisionScoreMet() + { + return IsSearchPrecisionScoreMet(Score); + } + + private bool IsSearchPrecisionScoreMet(int score) + { + var precisionScore = (SearchPrecisionScore)Enum.Parse( + typeof(SearchPrecisionScore), + UserSettingSearchPrecision ?? SearchPrecisionScore.Regular.ToString()); + return score >= (int)precisionScore; + } + + private int ApplySearchPrecisionFilter(int score) + { + return IsSearchPrecisionScoreMet(score) ? score : 0; + } } public class MatchOption