From 49c5c5bbdeb355541c587f9f60f5f432a491bc1d Mon Sep 17 00:00:00 2001 From: SysC0mp Date: Mon, 9 Dec 2019 20:57:59 +0100 Subject: [PATCH] Pass "ShouldUsePinyin" to StringMatcher Flag is used in method "ShouldUsePinyin()" to avoid calling Alphabet service. Otherwise, tests applying to StringMatcher.FuzzySearch() would fail because the pinyin helper library fails to initialize. --- Wox.Infrastructure/StringMatcher.cs | 8 +++++++- Wox.Infrastructure/UserSettings/Settings.cs | 12 +++++++++++- Wox/App.xaml.cs | 1 + 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Wox.Infrastructure/StringMatcher.cs b/Wox.Infrastructure/StringMatcher.cs index dd5a118fb4..baca1020f2 100644 --- a/Wox.Infrastructure/StringMatcher.cs +++ b/Wox.Infrastructure/StringMatcher.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -13,6 +13,7 @@ namespace Wox.Infrastructure public static MatchOption DefaultMatchOption = new MatchOption(); public static string UserSettingSearchPrecision { get; set; } + public static bool ShouldUsePinyin { get; set; } [Obsolete("This method is obsolete and should not be used. Please use the static function StringMatcher.FuzzySearch")] public static int Score(string source, string target) @@ -135,6 +136,11 @@ namespace Wox.Infrastructure public static int ScoreForPinyin(string source, string target) { + if (!ShouldUsePinyin) + { + return 0; + } + if (!string.IsNullOrEmpty(source) && !string.IsNullOrEmpty(target)) { if (Alphabet.ContainsChinese(source)) diff --git a/Wox.Infrastructure/UserSettings/Settings.cs b/Wox.Infrastructure/UserSettings/Settings.cs index 7371ea5d05..de5a2e6624 100644 --- a/Wox.Infrastructure/UserSettings/Settings.cs +++ b/Wox.Infrastructure/UserSettings/Settings.cs @@ -24,7 +24,17 @@ namespace Wox.Infrastructure.UserSettings /// /// when false Alphabet static service will always return empty results /// - public bool ShouldUsePinyin { get; set; } = true; + private bool _shouldUsePinyin = true; + public bool ShouldUsePinyin + { + get { return _shouldUsePinyin; } + set + { + _shouldUsePinyin = value; + StringMatcher.ShouldUsePinyin = value; + } + } + private string _querySearchPrecision { get; set; } = StringMatcher.SearchPrecisionScore.Regular.ToString(); public string QuerySearchPrecision diff --git a/Wox/App.xaml.cs b/Wox/App.xaml.cs index 8cdc4a8b85..9436df4758 100644 --- a/Wox/App.xaml.cs +++ b/Wox/App.xaml.cs @@ -56,6 +56,7 @@ namespace Wox Alphabet.Initialize(_settings); StringMatcher.UserSettingSearchPrecision = _settings.QuerySearchPrecision; + StringMatcher.ShouldUsePinyin = _settings.ShouldUsePinyin; PluginManager.LoadPlugins(_settings.PluginSettings); _mainVM = new MainViewModel(_settings);