Skip to content

Commit

Permalink
[launcher] - Increase the score for Exact matches in the Name of the …
Browse files Browse the repository at this point in the history
…Application (#3213)

* Increase score for exact matches in the name

* Added tests for exact matching

* Used TestCase

* variable for bonus score

* Removed comment, variable is self explanatory
  • Loading branch information
alekhyareddy28 committed May 19, 2020
1 parent 2e8602e commit f07d37c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
6 changes: 6 additions & 0 deletions src/modules/launcher/Wox.Infrastructure/StringMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ private static int CalculateSearchScore(string query, string stringToCompare, in
}
}

if (String.Equals(query, stringToCompare, StringComparison.CurrentCultureIgnoreCase))
{
var bonusForExactMatch = 10;
score += bonusForExactMatch;
}

return score;
}

Expand Down
27 changes: 15 additions & 12 deletions src/modules/launcher/Wox.Test/FuzzyMatcherTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,24 @@ public void WhenGivenStringsAndAppliedPrecisionFilteringThenShouldReturnGreaterT
}
}

[TestCase(Chrome, Chrome, 137)]
[TestCase(Chrome, LastIsChrome, 83)]
[TestCase(Chrome, HelpCureHopeRaiseOnMindEntityChrome, 21)]
[TestCase(Chrome, UninstallOrChangeProgramsOnYourComputer, 15)]
[TestCase(Chrome, CandyCrushSagaFromKing, 0)]
[TestCase("sql", MicrosoftSqlServerManagementStudio, 56)]
[TestCase("sql manag", MicrosoftSqlServerManagementStudio, 79)]//double spacing intended
public void WhenGivenQueryStringThenShouldReturnCurrentScoring(string queryString, string compareString, int expectedScore)
[TestCase("vim", "Vim", "ignoreDescription", "ignore.exe", "Vim Diff", "ignoreDescription", "ignore.exe")]
public void WhenMultipleResults_ExactMatchingResult_ShouldHaveGreatestScore(string queryString, string firstName, string firstDescription, string firstExecutableName, string secondName, string secondDescription, string secondExecutableName)
{
// When, Given
// Act
var matcher = new StringMatcher();
var rawScore = matcher.FuzzyMatch(queryString, compareString).RawScore;
var firstNameMatch = matcher.FuzzyMatch(queryString, firstName).RawScore;
var firstDescriptionMatch = matcher.FuzzyMatch(queryString, firstDescription).RawScore;
var firstExecutableNameMatch = matcher.FuzzyMatch(queryString, firstExecutableName).RawScore;

// Should
Assert.AreEqual(expectedScore, rawScore, $"Expected score for compare string '{compareString}': {expectedScore}, Actual: {rawScore}");
var secondNameMatch = matcher.FuzzyMatch(queryString, secondName).RawScore;
var secondDescriptionMatch = matcher.FuzzyMatch(queryString, secondDescription).RawScore;
var secondExecutableNameMatch = matcher.FuzzyMatch(queryString, secondExecutableName).RawScore;

var firstScore = new[] { firstNameMatch, firstDescriptionMatch, firstExecutableNameMatch }.Max();
var secondScore = new[] { secondNameMatch, secondDescriptionMatch, secondExecutableNameMatch }.Max();

// Assert
Assert.IsTrue(firstScore > secondScore);
}

[TestCase("goo", "Google Chrome", StringMatcher.SearchPrecisionScore.Regular, true)]
Expand Down

0 comments on commit f07d37c

Please sign in to comment.