mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 04:07:40 +02:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
@@ -8,9 +8,9 @@ namespace Wox.Plugin.BrowserBookmark.Commands
|
|||||||
{
|
{
|
||||||
internal static bool MatchProgram(Bookmark bookmark, string queryString)
|
internal static bool MatchProgram(Bookmark bookmark, string queryString)
|
||||||
{
|
{
|
||||||
if (StringMatcher.FuzzySearch(queryString, bookmark.Name, new MatchOption()).IsSearchPrecisionScoreMet()) return true;
|
if (StringMatcher.FuzzySearch(queryString, bookmark.Name).IsSearchPrecisionScoreMet()) return true;
|
||||||
if (StringMatcher.FuzzySearch(queryString, bookmark.PinyinName, new MatchOption()).IsSearchPrecisionScoreMet()) return true;
|
if (StringMatcher.FuzzySearch(queryString, bookmark.PinyinName).IsSearchPrecisionScoreMet()) return true;
|
||||||
if (StringMatcher.FuzzySearch(queryString, bookmark.Url, new MatchOption()).IsSearchPrecisionScoreMet()) return true;
|
if (StringMatcher.FuzzySearch(queryString, bookmark.Url).IsSearchPrecisionScoreMet()) return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ namespace Wox.Core.Plugin
|
|||||||
var rawQuery = string.Join(Query.TermSeperater, terms);
|
var rawQuery = string.Join(Query.TermSeperater, terms);
|
||||||
var actionKeyword = string.Empty;
|
var actionKeyword = string.Empty;
|
||||||
var search = rawQuery;
|
var search = rawQuery;
|
||||||
List<string> actionParameters = terms.ToList();
|
var actionParameters = terms.ToList();
|
||||||
if (terms.Length == 0) return null;
|
if (terms.Length == 0) return null;
|
||||||
if (NonGlobalPlugins.ContainsKey(terms[0]) &&
|
if (NonGlobalPlugins.ContainsKey(terms[0]) &&
|
||||||
!Settings.Plugins[NonGlobalPlugins[terms[0]].Metadata.ID].Disabled)
|
!Settings.Plugins[NonGlobalPlugins[terms[0]].Metadata.ID].Disabled)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace Wox.Infrastructure
|
|||||||
|
|
||||||
public static FuzzyMatcher Create(string query)
|
public static FuzzyMatcher Create(string query)
|
||||||
{
|
{
|
||||||
return new FuzzyMatcher(query, new MatchOption());
|
return new FuzzyMatcher(query, StringMatcher.DefaultMatchOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FuzzyMatcher Create(string query, MatchOption opt)
|
public static FuzzyMatcher Create(string query, MatchOption opt)
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ namespace Wox.Infrastructure
|
|||||||
{
|
{
|
||||||
public static class StringMatcher
|
public static class StringMatcher
|
||||||
{
|
{
|
||||||
|
public static MatchOption DefaultMatchOption = new MatchOption();
|
||||||
|
|
||||||
public static string UserSettingSearchPrecision { get; set; }
|
public static string UserSettingSearchPrecision { get; set; }
|
||||||
|
|
||||||
[Obsolete("This method is obsolete and should not be used. Please use the static function StringMatcher.FuzzySearch")]
|
[Obsolete("This method is obsolete and should not be used. Please use the static function StringMatcher.FuzzySearch")]
|
||||||
@@ -15,7 +17,7 @@ namespace Wox.Infrastructure
|
|||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(source) && !string.IsNullOrEmpty(target))
|
if (!string.IsNullOrEmpty(source) && !string.IsNullOrEmpty(target))
|
||||||
{
|
{
|
||||||
return FuzzySearch(target, source, new MatchOption()).Score;
|
return FuzzySearch(target, source, DefaultMatchOption).Score;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -26,12 +28,12 @@ namespace Wox.Infrastructure
|
|||||||
[Obsolete("This method is obsolete and should not be used. Please use the static function StringMatcher.FuzzySearch")]
|
[Obsolete("This method is obsolete and should not be used. Please use the static function StringMatcher.FuzzySearch")]
|
||||||
public static bool IsMatch(string source, string target)
|
public static bool IsMatch(string source, string target)
|
||||||
{
|
{
|
||||||
return FuzzySearch(target, source, new MatchOption()).Score > 0;
|
return FuzzySearch(target, source, DefaultMatchOption).Score > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MatchResult FuzzySearch(string query, string stringToCompare)
|
public static MatchResult FuzzySearch(string query, string stringToCompare)
|
||||||
{
|
{
|
||||||
return FuzzySearch(query, stringToCompare, new MatchOption());
|
return FuzzySearch(query, stringToCompare, DefaultMatchOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -41,7 +43,7 @@ namespace Wox.Infrastructure
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(stringToCompare) || string.IsNullOrEmpty(query)) return new MatchResult { Success = false };
|
if (string.IsNullOrEmpty(stringToCompare) || string.IsNullOrEmpty(query)) return new MatchResult { Success = false };
|
||||||
|
|
||||||
query.Trim();
|
query = query.Trim();
|
||||||
|
|
||||||
var len = stringToCompare.Length;
|
var len = stringToCompare.Length;
|
||||||
var compareString = opt.IgnoreCase ? stringToCompare.ToLower() : stringToCompare;
|
var compareString = opt.IgnoreCase ? stringToCompare.ToLower() : stringToCompare;
|
||||||
@@ -98,9 +100,9 @@ namespace Wox.Infrastructure
|
|||||||
var score = 100 * (query.Length + 1) / ((1 + firstIndex) + (matchLen + 1));
|
var score = 100 * (query.Length + 1) / ((1 + firstIndex) + (matchLen + 1));
|
||||||
//a match with less characters assigning more weights
|
//a match with less characters assigning more weights
|
||||||
if (stringToCompare.Length - query.Length < 5)
|
if (stringToCompare.Length - query.Length < 5)
|
||||||
score = score + 20;
|
score += 20;
|
||||||
else if (stringToCompare.Length - query.Length < 10)
|
else if (stringToCompare.Length - query.Length < 10)
|
||||||
score = score + 10;
|
score += 10;
|
||||||
|
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
@@ -139,10 +141,10 @@ namespace Wox.Infrastructure
|
|||||||
{
|
{
|
||||||
var combination = Alphabet.PinyinComination(source);
|
var combination = Alphabet.PinyinComination(source);
|
||||||
var pinyinScore = combination
|
var pinyinScore = combination
|
||||||
.Select(pinyin => FuzzySearch(target, string.Join("", pinyin), new MatchOption()).Score)
|
.Select(pinyin => FuzzySearch(target, string.Join("", pinyin)).Score)
|
||||||
.Max();
|
.Max();
|
||||||
var acronymScore = combination.Select(Alphabet.Acronym)
|
var acronymScore = combination.Select(Alphabet.Acronym)
|
||||||
.Select(pinyin => FuzzySearch(target, pinyin, new MatchOption()).Score)
|
.Select(pinyin => FuzzySearch(target, pinyin).Score)
|
||||||
.Max();
|
.Max();
|
||||||
var score = Math.Max(pinyinScore, acronymScore);
|
var score = Math.Max(pinyinScore, acronymScore);
|
||||||
return score;
|
return score;
|
||||||
@@ -163,8 +165,9 @@ namespace Wox.Infrastructure
|
|||||||
{
|
{
|
||||||
public bool Success { get; set; }
|
public bool Success { get; set; }
|
||||||
public int Score { get; set; }
|
public int Score { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// hightlight string
|
/// highlight string
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Value { get; set; }
|
public string Value { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,19 @@ namespace Wox.Plugin
|
|||||||
{
|
{
|
||||||
public class Query
|
public class Query
|
||||||
{
|
{
|
||||||
|
internal Query() { }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// to allow unit tests for plug ins
|
||||||
|
/// </summary>
|
||||||
|
public Query(string rawQuery, string search, string[] terms, string actionKeyword = "")
|
||||||
|
{
|
||||||
|
Search = search;
|
||||||
|
RawQuery = rawQuery;
|
||||||
|
Terms = terms;
|
||||||
|
ActionKeyword = actionKeyword;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Raw query, this includes action keyword if it has
|
/// Raw query, this includes action keyword if it has
|
||||||
/// We didn't recommend use this property directly. You should always use Search property.
|
/// We didn't recommend use this property directly. You should always use Search property.
|
||||||
|
|||||||
@@ -110,6 +110,6 @@ namespace Wox.Plugin
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Plugin ID that generate this result
|
/// Plugin ID that generate this result
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string PluginID { get; set; }
|
public string PluginID { get; internal set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,7 @@ namespace Wox.Test
|
|||||||
results.Add(new Result
|
results.Add(new Result
|
||||||
{
|
{
|
||||||
Title = str,
|
Title = str,
|
||||||
Score = StringMatcher.FuzzySearch("inst", str, new MatchOption()).Score
|
Score = StringMatcher.FuzzySearch("inst", str).Score
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ namespace Wox.Test
|
|||||||
{
|
{
|
||||||
var compareString = "Can have rum only in my glass";
|
var compareString = "Can have rum only in my glass";
|
||||||
|
|
||||||
var scoreResult = StringMatcher.FuzzySearch(searchString, compareString, new MatchOption()).Score;
|
var scoreResult = StringMatcher.FuzzySearch(searchString, compareString).Score;
|
||||||
|
|
||||||
Assert.True(scoreResult == 0);
|
Assert.True(scoreResult == 0);
|
||||||
}
|
}
|
||||||
@@ -92,7 +92,7 @@ namespace Wox.Test
|
|||||||
results.Add(new Result
|
results.Add(new Result
|
||||||
{
|
{
|
||||||
Title = str,
|
Title = str,
|
||||||
Score = StringMatcher.FuzzySearch(searchTerm, str, new MatchOption()).Score
|
Score = StringMatcher.FuzzySearch(searchTerm, str).Score
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ namespace Wox.Test
|
|||||||
results.Add(new Result
|
results.Add(new Result
|
||||||
{
|
{
|
||||||
Title = str,
|
Title = str,
|
||||||
Score = StringMatcher.FuzzySearch(searchTerm, str, new MatchOption()).Score
|
Score = StringMatcher.FuzzySearch(searchTerm, str).Score
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ namespace Wox.Test
|
|||||||
{
|
{
|
||||||
var expectedPrecisionString = (StringMatcher.SearchPrecisionScore)expectedPrecisionScore;
|
var expectedPrecisionString = (StringMatcher.SearchPrecisionScore)expectedPrecisionScore;
|
||||||
StringMatcher.UserSettingSearchPrecision = expectedPrecisionString.ToString();
|
StringMatcher.UserSettingSearchPrecision = expectedPrecisionString.ToString();
|
||||||
var matchResult = StringMatcher.FuzzySearch(queryString, compareString, new MatchOption());
|
var matchResult = StringMatcher.FuzzySearch(queryString, compareString);
|
||||||
|
|
||||||
Debug.WriteLine("");
|
Debug.WriteLine("");
|
||||||
Debug.WriteLine("###############################################");
|
Debug.WriteLine("###############################################");
|
||||||
|
|||||||
Reference in New Issue
Block a user