mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge bf579d1d90 into 24f6c90f72
This commit is contained in:
commit
63a0b2a163
3 changed files with 45 additions and 2 deletions
|
|
@ -41,7 +41,7 @@ namespace Flow.Launcher.Plugin.SharedModels
|
|||
/// <summary>
|
||||
/// The final score of the match result with search precision filters applied.
|
||||
/// </summary>
|
||||
public int Score { get; private set; }
|
||||
public int Score { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The raw calculated search score without any search precision filtering applied.
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FuzzySharp" Version="2.0.2" />
|
||||
<PackageReference Include="ini-parser" Version="2.5.2" />
|
||||
<PackageReference Include="MemoryPack" Version="1.21.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.9" />
|
||||
|
|
|
|||
|
|
@ -91,12 +91,26 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
if (candidates.Count == 0)
|
||||
return null;
|
||||
|
||||
var match = candidates.Select(candidate => Main.Context.API.FuzzySearch(query, candidate))
|
||||
var match = candidates.Select(candidate =>
|
||||
{
|
||||
var matchResult = Main.Context.API.FuzzySearch(query, candidate);
|
||||
matchResult.Score = FuzzySearch(query, candidate);
|
||||
return matchResult;
|
||||
})
|
||||
.MaxBy(match => match.Score);
|
||||
|
||||
return match?.IsSearchPrecisionScoreMet() ?? false ? match : null;
|
||||
}
|
||||
|
||||
private static int FuzzySearch(string query, string stringToCompare)
|
||||
{
|
||||
var newScore = FuzzySharp.Fuzz.PartialTokenSetRatio(query.ToLower(), stringToCompare.ToLower());
|
||||
if (stringToCompare.Length < query.Length)
|
||||
newScore = 0;
|
||||
|
||||
return newScore;
|
||||
}
|
||||
|
||||
public Result Result(string query, IPublicAPI api)
|
||||
{
|
||||
string title;
|
||||
|
|
@ -112,13 +126,16 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
{
|
||||
title = resultName;
|
||||
matchResult = Main.Context.API.FuzzySearch(query, resultName);
|
||||
matchResult.Score = FuzzySearch(query, resultName);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Search in both
|
||||
title = $"{resultName}: {Description}";
|
||||
var nameMatch = Main.Context.API.FuzzySearch(query, resultName);
|
||||
nameMatch.Score = FuzzySearch(query, resultName);
|
||||
var descriptionMatch = Main.Context.API.FuzzySearch(query, Description);
|
||||
descriptionMatch.Score = FuzzySearch(query, Description);
|
||||
if (descriptionMatch.Score > nameMatch.Score)
|
||||
{
|
||||
for (int i = 0; i < descriptionMatch.MatchData.Count; i++)
|
||||
|
|
@ -134,6 +151,31 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
}
|
||||
}
|
||||
|
||||
// if (!matchResult.IsSearchPrecisionScoreMet())
|
||||
// {
|
||||
// if (ExecutableName != null) // only lnk program will need this one
|
||||
// matchResult = StringMatcher.FuzzySearch(query, ExecutableName);
|
||||
//
|
||||
// if (!matchResult.IsSearchPrecisionScoreMet())
|
||||
// return null;
|
||||
//
|
||||
// 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.RawScore *= 10; // Bypass the SearchPrecisionScore and related tests
|
||||
matchResult.MatchData = new List<int>();
|
||||
|
||||
var result = new Result
|
||||
{
|
||||
Title = title + $"<{matchResult.Score}> <{newScore}> <{oldScore}>",
|
||||
SubTitle = LnkResolvedPath ?? FullPath,*/
|
||||
|
||||
List<string> candidates = new List<string>();
|
||||
|
||||
if (!matchResult.IsSearchPrecisionScoreMet() && !string.IsNullOrEmpty(query))
|
||||
|
|
|
|||
Loading…
Reference in a new issue