Skip to content

Commit 236ed5e

Browse files
authored
Merge pull request #15 from Flow-Launcher/fix_substring_scoring
Fix substring scoring
2 parents fbeed59 + 9386711 commit 236ed5e

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

Flow.Launcher.Infrastructure/StringMatcher.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,16 @@ private static int CalculateSearchScore(string query, string stringToCompare, in
212212
if (allSubstringsContainedInCompareString)
213213
{
214214
int count = query.Count(c => !char.IsWhiteSpace(c));
215-
int factor = count < 4 ? 10 : 5;
216-
score += factor * count;
215+
//10 per char is too much for long query strings, this threshhold is to avoid where long strings will override the other results too much
216+
int threshold = 4;
217+
if (count <= threshold)
218+
{
219+
score += count * 10;
220+
}
221+
else
222+
{
223+
score += threshold * 10 + (count - threshold) * 5;
224+
}
217225
}
218226

219227
return score;

Flow.Launcher.Test/FuzzyMatcherTest.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class FuzzyMatcherTest
1818
private const string LastIsChrome = "Last is chrome";
1919
private const string OneOneOneOne = "1111";
2020
private const string MicrosoftSqlServerManagementStudio = "Microsoft SQL Server Management Studio";
21+
private const string VisualStudioCode = "Visual Studio Code";
2122

2223
public List<string> GetSearchStrings()
2324
=> new List<string>
@@ -122,13 +123,13 @@ public void WhenGivenStringsAndAppliedPrecisionFilteringThenShouldReturnGreaterT
122123
}
123124
}
124125

125-
[TestCase(Chrome, Chrome, 137)]
126-
[TestCase(Chrome, LastIsChrome, 83)]
126+
[TestCase(Chrome, Chrome, 157)]
127+
[TestCase(Chrome, LastIsChrome, 103)]
127128
[TestCase(Chrome, HelpCureHopeRaiseOnMindEntityChrome, 21)]
128129
[TestCase(Chrome, UninstallOrChangeProgramsOnYourComputer, 15)]
129130
[TestCase(Chrome, CandyCrushSagaFromKing, 0)]
130131
[TestCase("sql", MicrosoftSqlServerManagementStudio, 56)]
131-
[TestCase("sql manag", MicrosoftSqlServerManagementStudio, 79)]//double spacing intended
132+
[TestCase("sql manag", MicrosoftSqlServerManagementStudio, 99)]//double spacing intended
132133
public void WhenGivenQueryStringThenShouldReturnCurrentScoring(string queryString, string compareString, int expectedScore)
133134
{
134135
// When, Given
@@ -195,6 +196,9 @@ public void WhenGivenDesiredPrecisionThenShouldReturnAllResultsGreaterOrEqual(
195196
[TestCase("ch r", "Change settings for text-to-speech and for speech recognition (if installed).", StringMatcher.SearchPrecisionScore.Regular, true)]
196197
[TestCase("a test", "This is a test", StringMatcher.SearchPrecisionScore.Regular, true)]
197198
[TestCase("test", "This is a test", StringMatcher.SearchPrecisionScore.Regular, true)]
199+
[TestCase("cod", VisualStudioCode, StringMatcher.SearchPrecisionScore.Regular, true)]
200+
[TestCase("code", VisualStudioCode, StringMatcher.SearchPrecisionScore.Regular, true)]
201+
[TestCase("codes", "Visual Studio Codes", StringMatcher.SearchPrecisionScore.Regular, true)]
198202
public void WhenGivenQueryShouldReturnResultsContainingAllQuerySubstrings(
199203
string queryString,
200204
string compareString,

0 commit comments

Comments
 (0)