Skip to content

Commit c89ab4e

Browse files
committed
Merge remote-tracking branch 'origin/dev' into dev
2 parents cb3e863 + ab05e34 commit c89ab4e

File tree

7 files changed

+36
-20
lines changed

7 files changed

+36
-20
lines changed

Plugins/Wox.Plugin.BrowserBookmark/Commands/Bookmarks.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ internal static class Bookmarks
88
{
99
internal static bool MatchProgram(Bookmark bookmark, string queryString)
1010
{
11-
if (StringMatcher.FuzzySearch(queryString, bookmark.Name, new MatchOption()).IsSearchPrecisionScoreMet()) return true;
12-
if (StringMatcher.FuzzySearch(queryString, bookmark.PinyinName, new MatchOption()).IsSearchPrecisionScoreMet()) return true;
13-
if (StringMatcher.FuzzySearch(queryString, bookmark.Url, new MatchOption()).IsSearchPrecisionScoreMet()) return true;
11+
if (StringMatcher.FuzzySearch(queryString, bookmark.Name).IsSearchPrecisionScoreMet()) return true;
12+
if (StringMatcher.FuzzySearch(queryString, bookmark.PinyinName).IsSearchPrecisionScoreMet()) return true;
13+
if (StringMatcher.FuzzySearch(queryString, bookmark.Url).IsSearchPrecisionScoreMet()) return true;
1414

1515
return false;
1616
}

Wox.Core/Plugin/PluginManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public static Query QueryInit(string text) //todo is that possible to move it in
135135
var rawQuery = string.Join(Query.TermSeperater, terms);
136136
var actionKeyword = string.Empty;
137137
var search = rawQuery;
138-
List<string> actionParameters = terms.ToList();
138+
var actionParameters = terms.ToList();
139139
if (terms.Length == 0) return null;
140140
if (NonGlobalPlugins.ContainsKey(terms[0]) &&
141141
!Settings.Plugins[NonGlobalPlugins[terms[0]].Metadata.ID].Disabled)

Wox.Infrastructure/FuzzyMatcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ private FuzzyMatcher(string query, MatchOption opt)
1616

1717
public static FuzzyMatcher Create(string query)
1818
{
19-
return new FuzzyMatcher(query, new MatchOption());
19+
return new FuzzyMatcher(query, StringMatcher.DefaultMatchOption);
2020
}
2121

2222
public static FuzzyMatcher Create(string query, MatchOption opt)

Wox.Infrastructure/StringMatcher.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ namespace Wox.Infrastructure
88
{
99
public static class StringMatcher
1010
{
11+
public static MatchOption DefaultMatchOption = new MatchOption();
12+
1113
public static string UserSettingSearchPrecision { get; set; }
1214

1315
[Obsolete("This method is obsolete and should not be used. Please use the static function StringMatcher.FuzzySearch")]
1416
public static int Score(string source, string target)
1517
{
1618
if (!string.IsNullOrEmpty(source) && !string.IsNullOrEmpty(target))
1719
{
18-
return FuzzySearch(target, source, new MatchOption()).Score;
20+
return FuzzySearch(target, source, DefaultMatchOption).Score;
1921
}
2022
else
2123
{
@@ -26,12 +28,12 @@ public static int Score(string source, string target)
2628
[Obsolete("This method is obsolete and should not be used. Please use the static function StringMatcher.FuzzySearch")]
2729
public static bool IsMatch(string source, string target)
2830
{
29-
return FuzzySearch(target, source, new MatchOption()).Score > 0;
31+
return FuzzySearch(target, source, DefaultMatchOption).Score > 0;
3032
}
3133

3234
public static MatchResult FuzzySearch(string query, string stringToCompare)
3335
{
34-
return FuzzySearch(query, stringToCompare, new MatchOption());
36+
return FuzzySearch(query, stringToCompare, DefaultMatchOption);
3537
}
3638

3739
/// <summary>
@@ -41,7 +43,7 @@ public static MatchResult FuzzySearch(string query, string stringToCompare, Matc
4143
{
4244
if (string.IsNullOrEmpty(stringToCompare) || string.IsNullOrEmpty(query)) return new MatchResult { Success = false };
4345

44-
query.Trim();
46+
query = query.Trim();
4547

4648
var len = stringToCompare.Length;
4749
var compareString = opt.IgnoreCase ? stringToCompare.ToLower() : stringToCompare;
@@ -98,9 +100,9 @@ private static int CalScore(string query, string stringToCompare, int firstIndex
98100
var score = 100 * (query.Length + 1) / ((1 + firstIndex) + (matchLen + 1));
99101
//a match with less characters assigning more weights
100102
if (stringToCompare.Length - query.Length < 5)
101-
score = score + 20;
103+
score += 20;
102104
else if (stringToCompare.Length - query.Length < 10)
103-
score = score + 10;
105+
score += 10;
104106

105107
return score;
106108
}
@@ -139,10 +141,10 @@ public static int ScoreForPinyin(string source, string target)
139141
{
140142
var combination = Alphabet.PinyinComination(source);
141143
var pinyinScore = combination
142-
.Select(pinyin => FuzzySearch(target, string.Join("", pinyin), new MatchOption()).Score)
144+
.Select(pinyin => FuzzySearch(target, string.Join("", pinyin)).Score)
143145
.Max();
144146
var acronymScore = combination.Select(Alphabet.Acronym)
145-
.Select(pinyin => FuzzySearch(target, pinyin, new MatchOption()).Score)
147+
.Select(pinyin => FuzzySearch(target, pinyin).Score)
146148
.Max();
147149
var score = Math.Max(pinyinScore, acronymScore);
148150
return score;
@@ -163,8 +165,9 @@ public class MatchResult
163165
{
164166
public bool Success { get; set; }
165167
public int Score { get; set; }
168+
166169
/// <summary>
167-
/// hightlight string
170+
/// highlight string
168171
/// </summary>
169172
public string Value { get; set; }
170173
}

Wox.Plugin/Query.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ namespace Wox.Plugin
66
{
77
public class Query
88
{
9+
internal Query() { }
10+
11+
/// <summary>
12+
/// to allow unit tests for plug ins
13+
/// </summary>
14+
public Query(string rawQuery, string search, string[] terms, string actionKeyword = "")
15+
{
16+
Search = search;
17+
RawQuery = rawQuery;
18+
Terms = terms;
19+
ActionKeyword = actionKeyword;
20+
}
21+
922
/// <summary>
1023
/// Raw query, this includes action keyword if it has
1124
/// We didn't recommend use this property directly. You should always use Search property.

Wox.Plugin/Result.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,6 @@ public Result() { }
110110
/// <summary>
111111
/// Plugin ID that generate this result
112112
/// </summary>
113-
public string PluginID { get; set; }
113+
public string PluginID { get; internal set; }
114114
}
115115
}

Wox.Test/FuzzyMatcherTest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void MatchTest()
5555
results.Add(new Result
5656
{
5757
Title = str,
58-
Score = StringMatcher.FuzzySearch("inst", str, new MatchOption()).Score
58+
Score = StringMatcher.FuzzySearch("inst", str).Score
5959
});
6060
}
6161

@@ -72,7 +72,7 @@ public void WhenGivenNotAllCharactersFoundInSearchStringThenShouldReturnZeroScor
7272
{
7373
var compareString = "Can have rum only in my glass";
7474

75-
var scoreResult = StringMatcher.FuzzySearch(searchString, compareString, new MatchOption()).Score;
75+
var scoreResult = StringMatcher.FuzzySearch(searchString, compareString).Score;
7676

7777
Assert.True(scoreResult == 0);
7878
}
@@ -92,7 +92,7 @@ public void WhenGivenStringsAndAppliedPrecisionFilteringThenShouldReturnGreaterT
9292
results.Add(new Result
9393
{
9494
Title = str,
95-
Score = StringMatcher.FuzzySearch(searchTerm, str, new MatchOption()).Score
95+
Score = StringMatcher.FuzzySearch(searchTerm, str).Score
9696
});
9797
}
9898

@@ -135,7 +135,7 @@ public void WhenGivenStringsForCalScoreMethodThenShouldReturnCurrentScoring(stri
135135
results.Add(new Result
136136
{
137137
Title = str,
138-
Score = StringMatcher.FuzzySearch(searchTerm, str, new MatchOption()).Score
138+
Score = StringMatcher.FuzzySearch(searchTerm, str).Score
139139
});
140140
}
141141

@@ -173,7 +173,7 @@ public void WhenGivenDesiredPrecisionThenShouldReturnAllResultsGreaterOrEqual(st
173173
{
174174
var expectedPrecisionString = (StringMatcher.SearchPrecisionScore)expectedPrecisionScore;
175175
StringMatcher.UserSettingSearchPrecision = expectedPrecisionString.ToString();
176-
var matchResult = StringMatcher.FuzzySearch(queryString, compareString, new MatchOption());
176+
var matchResult = StringMatcher.FuzzySearch(queryString, compareString);
177177

178178
Debug.WriteLine("");
179179
Debug.WriteLine("###############################################");

0 commit comments

Comments
 (0)