mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #15 from Flow-Launcher/fix_substring_scoring
Fix substring scoring
This commit is contained in:
commit
236ed5edcd
2 changed files with 17 additions and 5 deletions
|
|
@ -212,8 +212,16 @@ namespace Flow.Launcher.Infrastructure
|
||||||
if (allSubstringsContainedInCompareString)
|
if (allSubstringsContainedInCompareString)
|
||||||
{
|
{
|
||||||
int count = query.Count(c => !char.IsWhiteSpace(c));
|
int count = query.Count(c => !char.IsWhiteSpace(c));
|
||||||
int factor = count < 4 ? 10 : 5;
|
//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
|
||||||
score += factor * count;
|
int threshold = 4;
|
||||||
|
if (count <= threshold)
|
||||||
|
{
|
||||||
|
score += count * 10;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
score += threshold * 10 + (count - threshold) * 5;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return score;
|
return score;
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ namespace Flow.Launcher.Test
|
||||||
private const string LastIsChrome = "Last is chrome";
|
private const string LastIsChrome = "Last is chrome";
|
||||||
private const string OneOneOneOne = "1111";
|
private const string OneOneOneOne = "1111";
|
||||||
private const string MicrosoftSqlServerManagementStudio = "Microsoft SQL Server Management Studio";
|
private const string MicrosoftSqlServerManagementStudio = "Microsoft SQL Server Management Studio";
|
||||||
|
private const string VisualStudioCode = "Visual Studio Code";
|
||||||
|
|
||||||
public List<string> GetSearchStrings()
|
public List<string> GetSearchStrings()
|
||||||
=> new List<string>
|
=> new List<string>
|
||||||
|
|
@ -122,13 +123,13 @@ namespace Flow.Launcher.Test
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestCase(Chrome, Chrome, 137)]
|
[TestCase(Chrome, Chrome, 157)]
|
||||||
[TestCase(Chrome, LastIsChrome, 83)]
|
[TestCase(Chrome, LastIsChrome, 103)]
|
||||||
[TestCase(Chrome, HelpCureHopeRaiseOnMindEntityChrome, 21)]
|
[TestCase(Chrome, HelpCureHopeRaiseOnMindEntityChrome, 21)]
|
||||||
[TestCase(Chrome, UninstallOrChangeProgramsOnYourComputer, 15)]
|
[TestCase(Chrome, UninstallOrChangeProgramsOnYourComputer, 15)]
|
||||||
[TestCase(Chrome, CandyCrushSagaFromKing, 0)]
|
[TestCase(Chrome, CandyCrushSagaFromKing, 0)]
|
||||||
[TestCase("sql", MicrosoftSqlServerManagementStudio, 56)]
|
[TestCase("sql", MicrosoftSqlServerManagementStudio, 56)]
|
||||||
[TestCase("sql manag", MicrosoftSqlServerManagementStudio, 79)]//double spacing intended
|
[TestCase("sql manag", MicrosoftSqlServerManagementStudio, 99)]//double spacing intended
|
||||||
public void WhenGivenQueryStringThenShouldReturnCurrentScoring(string queryString, string compareString, int expectedScore)
|
public void WhenGivenQueryStringThenShouldReturnCurrentScoring(string queryString, string compareString, int expectedScore)
|
||||||
{
|
{
|
||||||
// When, Given
|
// When, Given
|
||||||
|
|
@ -195,6 +196,9 @@ namespace Flow.Launcher.Test
|
||||||
[TestCase("ch r", "Change settings for text-to-speech and for speech recognition (if installed).", StringMatcher.SearchPrecisionScore.Regular, true)]
|
[TestCase("ch r", "Change settings for text-to-speech and for speech recognition (if installed).", StringMatcher.SearchPrecisionScore.Regular, true)]
|
||||||
[TestCase("a test", "This is a test", StringMatcher.SearchPrecisionScore.Regular, true)]
|
[TestCase("a test", "This is a test", StringMatcher.SearchPrecisionScore.Regular, true)]
|
||||||
[TestCase("test", "This is a test", StringMatcher.SearchPrecisionScore.Regular, true)]
|
[TestCase("test", "This is a test", StringMatcher.SearchPrecisionScore.Regular, true)]
|
||||||
|
[TestCase("cod", VisualStudioCode, StringMatcher.SearchPrecisionScore.Regular, true)]
|
||||||
|
[TestCase("code", VisualStudioCode, StringMatcher.SearchPrecisionScore.Regular, true)]
|
||||||
|
[TestCase("codes", "Visual Studio Codes", StringMatcher.SearchPrecisionScore.Regular, true)]
|
||||||
public void WhenGivenQueryShouldReturnResultsContainingAllQuerySubstrings(
|
public void WhenGivenQueryShouldReturnResultsContainingAllQuerySubstrings(
|
||||||
string queryString,
|
string queryString,
|
||||||
string compareString,
|
string compareString,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue