diff --git a/src/modules/launcher/Wox.Infrastructure/StringMatcher.cs b/src/modules/launcher/Wox.Infrastructure/StringMatcher.cs index ef3e1045b2..fd64c4391c 100644 --- a/src/modules/launcher/Wox.Infrastructure/StringMatcher.cs +++ b/src/modules/launcher/Wox.Infrastructure/StringMatcher.cs @@ -223,6 +223,12 @@ namespace Wox.Infrastructure } } + if (String.Equals(query, stringToCompare, StringComparison.CurrentCultureIgnoreCase)) + { + var bonusForExactMatch = 10; + score += bonusForExactMatch; + } + return score; } diff --git a/src/modules/launcher/Wox.Test/FuzzyMatcherTest.cs b/src/modules/launcher/Wox.Test/FuzzyMatcherTest.cs index 011f050ac1..cce73f7482 100644 --- a/src/modules/launcher/Wox.Test/FuzzyMatcherTest.cs +++ b/src/modules/launcher/Wox.Test/FuzzyMatcherTest.cs @@ -122,21 +122,24 @@ namespace Wox.Test } } - [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)]