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.
This commit is contained in:
SysC0mp 2019-12-09 20:57:59 +01:00
parent 78f243651e
commit 49c5c5bbde
3 changed files with 19 additions and 2 deletions

View File

@ -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))

View File

@ -24,7 +24,17 @@ namespace Wox.Infrastructure.UserSettings
/// <summary>
/// when false Alphabet static service will always return empty results
/// </summary>
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

View File

@ -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);