mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Split name matching and desciption matching due to fuzzy change
This commit is contained in:
parent
8fb2dad65c
commit
f32cbaf331
2 changed files with 71 additions and 33 deletions
|
|
@ -206,7 +206,7 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
ProgramLogger.LogException("UWP" ,"CurrentUserPackages", $"id","An unexpected error occured and "
|
ProgramLogger.LogException("UWP", "CurrentUserPackages", $"id", "An unexpected error occured and "
|
||||||
+ $"unable to verify if package is valid", e);
|
+ $"unable to verify if package is valid", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -263,24 +263,42 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
||||||
public string LogoPath { get; set; }
|
public string LogoPath { get; set; }
|
||||||
public UWP Package { get; set; }
|
public UWP Package { get; set; }
|
||||||
|
|
||||||
public Application(){}
|
public Application() { }
|
||||||
|
|
||||||
|
|
||||||
public Result Result(string query, IPublicAPI api)
|
public Result Result(string query, IPublicAPI api)
|
||||||
{
|
{
|
||||||
var title = (Name, Description) switch
|
string title;
|
||||||
|
MatchResult matchResult;
|
||||||
|
|
||||||
|
// We suppose Name won't be null
|
||||||
|
if (Description == null || Name.StartsWith(Description))
|
||||||
{
|
{
|
||||||
(var n, null) => n,
|
title = Name;
|
||||||
(var n, var d) when d.StartsWith(n) => d,
|
matchResult = StringMatcher.FuzzySearch(query, title);
|
||||||
(var n, var d) when n.StartsWith(d) => n,
|
}
|
||||||
(var n, var d) when !string.IsNullOrEmpty(d) => $"{n}: {d}",
|
else if (Description.StartsWith(Name))
|
||||||
_ => Name
|
{
|
||||||
};
|
title = Description;
|
||||||
|
matchResult = StringMatcher.FuzzySearch(query, Description);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
title = $"{Name}: {Description}";
|
||||||
|
var nameMatch = StringMatcher.FuzzySearch(query, Name);
|
||||||
|
var desciptionMatch = StringMatcher.FuzzySearch(query, Description);
|
||||||
|
if (desciptionMatch.Score > nameMatch.Score)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < desciptionMatch.MatchData.Count; i++)
|
||||||
|
{
|
||||||
|
desciptionMatch.MatchData[i] += Name.Length + 2; // 2 is ": "
|
||||||
|
}
|
||||||
|
matchResult = desciptionMatch;
|
||||||
|
}
|
||||||
|
else matchResult = nameMatch;
|
||||||
|
}
|
||||||
|
|
||||||
var matchResult = StringMatcher.FuzzySearch(query, title);
|
if (!matchResult.Success) return null;
|
||||||
|
|
||||||
if (!matchResult.Success)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
var result = new Result
|
var result = new Result
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ using Shell;
|
||||||
using Flow.Launcher.Infrastructure;
|
using Flow.Launcher.Infrastructure;
|
||||||
using Flow.Launcher.Plugin.Program.Logger;
|
using Flow.Launcher.Plugin.Program.Logger;
|
||||||
using Flow.Launcher.Plugin.SharedCommands;
|
using Flow.Launcher.Plugin.SharedCommands;
|
||||||
|
using Flow.Launcher.Plugin.SharedModels;
|
||||||
|
|
||||||
namespace Flow.Launcher.Plugin.Program.Programs
|
namespace Flow.Launcher.Plugin.Program.Programs
|
||||||
{
|
{
|
||||||
|
|
@ -36,19 +37,38 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
||||||
|
|
||||||
public Result Result(string query, IPublicAPI api)
|
public Result Result(string query, IPublicAPI api)
|
||||||
{
|
{
|
||||||
var title = (Name, Description) switch
|
string title;
|
||||||
|
MatchResult matchResult;
|
||||||
|
|
||||||
|
// We suppose Name won't be null
|
||||||
|
if (Description == null || Name.StartsWith(Description))
|
||||||
{
|
{
|
||||||
(var n, null) => n,
|
title = Name;
|
||||||
(var n, var d) when d.StartsWith(n) => d,
|
matchResult = StringMatcher.FuzzySearch(query, title);
|
||||||
(var n, var d) when n.StartsWith(d) => n,
|
}
|
||||||
(var n, var d) when !string.IsNullOrEmpty(d) => $"{n}: {d}",
|
else if (Description.StartsWith(Name))
|
||||||
_ => Name
|
{
|
||||||
};
|
title = Description;
|
||||||
|
matchResult = StringMatcher.FuzzySearch(query, Description);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
title = $"{Name}: {Description}";
|
||||||
|
var nameMatch = StringMatcher.FuzzySearch(query, Name);
|
||||||
|
var desciptionMatch = StringMatcher.FuzzySearch(query, Description);
|
||||||
|
if (desciptionMatch.Score > nameMatch.Score)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < desciptionMatch.MatchData.Count; i++)
|
||||||
|
{
|
||||||
|
desciptionMatch.MatchData[i] += Name.Length + 2; // 2 is ": "
|
||||||
|
}
|
||||||
|
matchResult = desciptionMatch;
|
||||||
|
}
|
||||||
|
else matchResult = nameMatch;
|
||||||
|
}
|
||||||
|
|
||||||
var matchResult = StringMatcher.FuzzySearch(query, title);
|
if (!matchResult.Success) return null;
|
||||||
|
|
||||||
if (!matchResult.Success)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
var result = new Result
|
var result = new Result
|
||||||
{
|
{
|
||||||
|
|
@ -58,7 +78,7 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
||||||
Score = matchResult.Score,
|
Score = matchResult.Score,
|
||||||
TitleHighlightData = matchResult.MatchData,
|
TitleHighlightData = matchResult.MatchData,
|
||||||
ContextData = this,
|
ContextData = this,
|
||||||
Action = e =>
|
Action = _ =>
|
||||||
{
|
{
|
||||||
var info = new ProcessStartInfo
|
var info = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
|
|
@ -268,10 +288,10 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var paths = Directory.EnumerateFiles(directory, "*", new EnumerationOptions
|
var paths = Directory.EnumerateFiles(directory, "*", new EnumerationOptions
|
||||||
{
|
{
|
||||||
IgnoreInaccessible = true,
|
IgnoreInaccessible = true,
|
||||||
RecurseSubdirectories = true
|
RecurseSubdirectories = true
|
||||||
})
|
})
|
||||||
.Where(x => suffixes.Contains(Extension(x)));
|
.Where(x => suffixes.Contains(Extension(x)));
|
||||||
|
|
||||||
return paths;
|
return paths;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue