Fix pinyin fuzzysearch (#131)

* fix typo

* make function obsolete 

it is not used in the code

* rewrite the function that converts chinese chars to pinyin

1. Only difference in this rewrite is instead of returning 2D array, return as a combined single string of all the possible pinyin combination. Since fuzzy search does character matching, this shouldn't be a problem.

2. Added a function that returns a custom language converter. In this case Pinyin converter. New converters can be added.

* Use new language converter param + strip out ScoreForPinyin method

* update

* Change parameter name

* fix failing tests

* WIP

* Remove todo

There should be some distinction between score after precision filter and actual raw score derived from FuzzySearch. Although so far RawScore is used in testing, but it seems to describe the structure. Originally it was to avoid assigning score directly as it would be hard to reason about that output of FuzzySearch score is.

* Add constructors, remove default to enforce required properties

* remove setting rawscore in SearchPrecision

* Change method name to reflect intention

* Change parameter name + update comment

* update

* Remove params comment

Co-authored-by: theClueless <14300910+theClueless@users.noreply.github.com>
This commit is contained in:
Jeremy Wu
2020-01-20 10:06:16 +11:00
committed by theClueless
parent ee93f7e018
commit 07310c7714
7 changed files with 133 additions and 122 deletions

View File

@@ -57,12 +57,13 @@ namespace Wox.Test
};
var results = new List<Result>();
var matcher = new StringMatcher();
foreach (var str in sources)
{
results.Add(new Result
{
Title = str,
Score = StringMatcher.FuzzySearch("inst", str).RawScore
Score = matcher.FuzzyMatch("inst", str).RawScore
});
}
@@ -78,8 +79,8 @@ namespace Wox.Test
public void WhenGivenNotAllCharactersFoundInSearchStringThenShouldReturnZeroScore(string searchString)
{
var compareString = "Can have rum only in my glass";
var scoreResult = StringMatcher.FuzzySearch(searchString, compareString).RawScore;
var matcher = new StringMatcher();
var scoreResult = matcher.FuzzyMatch(searchString, compareString).RawScore;
Assert.True(scoreResult == 0);
}
@@ -93,13 +94,13 @@ namespace Wox.Test
public void WhenGivenStringsAndAppliedPrecisionFilteringThenShouldReturnGreaterThanPrecisionScoreResults(string searchTerm)
{
var results = new List<Result>();
var matcher = new StringMatcher();
foreach (var str in GetSearchStrings())
{
results.Add(new Result
{
Title = str,
Score = StringMatcher.FuzzySearch(searchTerm, str).Score
Score = matcher.FuzzyMatch(searchTerm, str).Score
});
}
@@ -131,7 +132,8 @@ namespace Wox.Test
public void WhenGivenQueryStringThenShouldReturnCurrentScoring(string queryString, string compareString, int expectedScore)
{
// When, Given
var rawScore = StringMatcher.FuzzySearch(queryString, compareString).RawScore;
var matcher = new StringMatcher();
var rawScore = matcher.FuzzyMatch(queryString, compareString).RawScore;
// Should
Assert.AreEqual(expectedScore, rawScore, $"Expected score for compare string '{compareString}': {expectedScore}, Actual: {rawScore}");
@@ -154,10 +156,10 @@ namespace Wox.Test
bool expectedPrecisionResult)
{
// When
StringMatcher.UserSettingSearchPrecision = expectedPrecisionScore;
var matcher = new StringMatcher {UserSettingSearchPrecision = expectedPrecisionScore};
// Given
var matchResult = StringMatcher.FuzzySearch(queryString, compareString);
var matchResult = matcher.FuzzyMatch(queryString, compareString);
Debug.WriteLine("");
Debug.WriteLine("###############################################");
@@ -200,10 +202,10 @@ namespace Wox.Test
bool expectedPrecisionResult)
{
// When
StringMatcher.UserSettingSearchPrecision = expectedPrecisionScore;
var matcher = new StringMatcher { UserSettingSearchPrecision = expectedPrecisionScore };
// Given
var matchResult = StringMatcher.FuzzySearch(queryString, compareString);
var matchResult = matcher.FuzzyMatch(queryString, compareString);
Debug.WriteLine("");
Debug.WriteLine("###############################################");