mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
feat(StringMatcher): add Chinese PinYin support option
- Add ChinesePinYinSupport property to MatchOption class - Implement Chinese PinYin support in StringMatcher class - Implement Chinese PinYin support in FuzzyStringMatcher class - Use the new option to conditionally enable Chinese PinYin matching Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
This commit is contained in:
@@ -7,4 +7,9 @@ namespace Common.Search.FuzzSearch;
|
||||
public class MatchOption
|
||||
{
|
||||
public bool IgnoreCase { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether to support Chinese PinYin
|
||||
/// </summary>
|
||||
public bool ChinesePinYinSupport { get; set; }
|
||||
}
|
||||
|
||||
@@ -43,8 +43,7 @@ public class StringMatcher
|
||||
List<string> queryList = [query];
|
||||
List<string> stringToCompareList = [stringToCompare];
|
||||
|
||||
// TODO: Add switch for Chinese.
|
||||
if (true)
|
||||
if (opt.ChinesePinYinSupport)
|
||||
{
|
||||
// Remove IME composition split characters.
|
||||
var input = query.Replace("'", string.Empty);
|
||||
|
||||
@@ -44,7 +44,17 @@ public partial class SettingsModel : ObservableObject
|
||||
|
||||
public bool AllowExternalReload { get; set; }
|
||||
|
||||
public bool EnableChinesePinYinSupport { get; set; }
|
||||
public bool EnableChinesePinYinSupport
|
||||
{
|
||||
get => field;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref field, value))
|
||||
{
|
||||
FuzzyStringMatcher.ChinesePinYinSupport = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<string, ProviderSettings> ProviderSettings { get; set; } = [];
|
||||
|
||||
|
||||
@@ -11,6 +11,11 @@ public static class FuzzyStringMatcher
|
||||
{
|
||||
private const int NOMATCH = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether to support Chinese PinYin
|
||||
/// </summary>
|
||||
public static bool ChinesePinYinSupport { get; set; }
|
||||
|
||||
public static int ScoreFuzzy(string needle, string haystack, bool allowNonContiguousMatches = true)
|
||||
{
|
||||
var (s, _) = ScoreFuzzyWithPositions(needle, haystack, allowNonContiguousMatches);
|
||||
@@ -25,8 +30,7 @@ public static class FuzzyStringMatcher
|
||||
List<string> needles = [needle];
|
||||
List<string> haystacks = [haystack];
|
||||
|
||||
// TODO: Add switch for Chinese.
|
||||
if (true)
|
||||
if (ChinesePinYinSupport)
|
||||
{
|
||||
// Remove IME composition split characters.
|
||||
var input = needle.Replace("'", string.Empty);
|
||||
|
||||
Reference in New Issue
Block a user