Add demo for FuzzySharp (Levenshtein)

This commit is contained in:
pc223 2021-07-29 09:43:32 +07:00
parent 309ee29bda
commit 68811fa324
3 changed files with 20 additions and 3 deletions

View file

@ -65,8 +65,8 @@ namespace Flow.Launcher.Plugin.SharedModels
public enum SearchPrecisionScore
{
Regular = 50,
Low = 20,
Regular = 0,
Low = 0,
None = 0
}
}

View file

@ -58,6 +58,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="FuzzySharp" Version="2.0.2" />
<PackageReference Include="System.Runtime" Version="4.3.1" />
</ItemGroup>

View file

@ -93,10 +93,26 @@ namespace Flow.Launcher.Plugin.Program.Programs
matchResult.MatchData = new List<int>();
}
var newScore = FuzzySharp.Fuzz.PartialTokenSetRatio(query.ToLower(), Name.ToLower());
if (Name.Length < query.Length)
newScore = 0;
var oldScore = matchResult.RawScore;
matchResult.RawScore = Math.Max(newScore, oldScore);
matchResult.MatchData = new List<int>();
var result = new Result
{
Title = title,
Title = title + $"<{matchResult.Score}> <{newScore}> <{oldScore}>",
SubTitle = LnkResolvedPath ?? FullPath,
IcoPath = IcoPath,
Score = matchResult.Score,