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 public enum SearchPrecisionScore
{ {
Regular = 50, Regular = 0,
Low = 20, Low = 0,
None = 0 None = 0
} }
} }

View file

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

View file

@ -94,9 +94,25 @@ namespace Flow.Launcher.Plugin.Program.Programs
matchResult.MatchData = new List<int>(); 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 var result = new Result
{ {
Title = title, Title = title + $"<{matchResult.Score}> <{newScore}> <{oldScore}>",
SubTitle = LnkResolvedPath ?? FullPath, SubTitle = LnkResolvedPath ?? FullPath,
IcoPath = IcoPath, IcoPath = IcoPath,
Score = matchResult.Score, Score = matchResult.Score,