Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Jeremy Wu
2019-10-27 12:22:31 +11:00
7 changed files with 36 additions and 20 deletions

View File

@@ -8,9 +8,9 @@ namespace Wox.Plugin.BrowserBookmark.Commands
{
internal static bool MatchProgram(Bookmark bookmark, string queryString)
{
if (StringMatcher.FuzzySearch(queryString, bookmark.Name, new MatchOption()).IsSearchPrecisionScoreMet()) return true;
if (StringMatcher.FuzzySearch(queryString, bookmark.PinyinName, new MatchOption()).IsSearchPrecisionScoreMet()) return true;
if (StringMatcher.FuzzySearch(queryString, bookmark.Url, new MatchOption()).IsSearchPrecisionScoreMet()) return true;
if (StringMatcher.FuzzySearch(queryString, bookmark.Name).IsSearchPrecisionScoreMet()) return true;
if (StringMatcher.FuzzySearch(queryString, bookmark.PinyinName).IsSearchPrecisionScoreMet()) return true;
if (StringMatcher.FuzzySearch(queryString, bookmark.Url).IsSearchPrecisionScoreMet()) return true;
return false;
}

View File

@@ -135,7 +135,7 @@ namespace Wox.Core.Plugin
var rawQuery = string.Join(Query.TermSeperater, terms);
var actionKeyword = string.Empty;
var search = rawQuery;
List<string> actionParameters = terms.ToList();
var actionParameters = terms.ToList();
if (terms.Length == 0) return null;
if (NonGlobalPlugins.ContainsKey(terms[0]) &&
!Settings.Plugins[NonGlobalPlugins[terms[0]].Metadata.ID].Disabled)

View File

@@ -16,7 +16,7 @@ namespace Wox.Infrastructure
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)

View File

@@ -8,6 +8,8 @@ namespace Wox.Infrastructure
{
public static class StringMatcher
{
public static MatchOption DefaultMatchOption = new MatchOption();
public static string UserSettingSearchPrecision { get; set; }
[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))
{
return FuzzySearch(target, source, new MatchOption()).Score;
return FuzzySearch(target, source, DefaultMatchOption).Score;
}
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")]
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)
{
return FuzzySearch(query, stringToCompare, new MatchOption());
return FuzzySearch(query, stringToCompare, DefaultMatchOption);
}
/// <summary>
@@ -41,7 +43,7 @@ namespace Wox.Infrastructure
{
if (string.IsNullOrEmpty(stringToCompare) || string.IsNullOrEmpty(query)) return new MatchResult { Success = false };
query.Trim();
query = query.Trim();
var len = stringToCompare.Length;
var compareString = opt.IgnoreCase ? stringToCompare.ToLower() : stringToCompare;
@@ -98,9 +100,9 @@ namespace Wox.Infrastructure
var score = 100 * (query.Length + 1) / ((1 + firstIndex) + (matchLen + 1));
//a match with less characters assigning more weights
if (stringToCompare.Length - query.Length < 5)
score = score + 20;
score += 20;
else if (stringToCompare.Length - query.Length < 10)
score = score + 10;
score += 10;
return score;
}
@@ -139,10 +141,10 @@ namespace Wox.Infrastructure
{
var combination = Alphabet.PinyinComination(source);
var pinyinScore = combination
.Select(pinyin => FuzzySearch(target, string.Join("", pinyin), new MatchOption()).Score)
.Select(pinyin => FuzzySearch(target, string.Join("", pinyin)).Score)
.Max();
var acronymScore = combination.Select(Alphabet.Acronym)
.Select(pinyin => FuzzySearch(target, pinyin, new MatchOption()).Score)
.Select(pinyin => FuzzySearch(target, pinyin).Score)
.Max();
var score = Math.Max(pinyinScore, acronymScore);
return score;
@@ -163,8 +165,9 @@ namespace Wox.Infrastructure
{
public bool Success { get; set; }
public int Score { get; set; }
/// <summary>
/// hightlight string
/// highlight string
/// </summary>
public string Value { get; set; }
}

View File

@@ -6,6 +6,19 @@ namespace Wox.Plugin
{
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>
/// Raw query, this includes action keyword if it has
/// We didn't recommend use this property directly. You should always use Search property.

View File

@@ -110,6 +110,6 @@ namespace Wox.Plugin
/// <summary>
/// Plugin ID that generate this result
/// </summary>
public string PluginID { get; set; }
public string PluginID { get; internal set; }
}
}

View File

@@ -55,7 +55,7 @@ namespace Wox.Test
results.Add(new Result
{
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 scoreResult = StringMatcher.FuzzySearch(searchString, compareString, new MatchOption()).Score;
var scoreResult = StringMatcher.FuzzySearch(searchString, compareString).Score;
Assert.True(scoreResult == 0);
}
@@ -92,7 +92,7 @@ namespace Wox.Test
results.Add(new Result
{
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
{
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;
StringMatcher.UserSettingSearchPrecision = expectedPrecisionString.ToString();
var matchResult = StringMatcher.FuzzySearch(queryString, compareString, new MatchOption());
var matchResult = StringMatcher.FuzzySearch(queryString, compareString);
Debug.WriteLine("");
Debug.WriteLine("###############################################");