mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
remove extra fuzzy search
Co-authored-by: Qian Bao <bao.github@outlook.com>
This commit is contained in:
parent
86edae2bc6
commit
04ee651b64
2 changed files with 31 additions and 61 deletions
|
|
@ -265,27 +265,30 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
|
||||
public Application(){}
|
||||
|
||||
private int Score(string query)
|
||||
{
|
||||
var displayNameMatch = StringMatcher.FuzzySearch(query, DisplayName);
|
||||
var descriptionMatch = StringMatcher.FuzzySearch(query, Description);
|
||||
var score = new[] { displayNameMatch.Score, descriptionMatch.Score }.Max();
|
||||
return score;
|
||||
}
|
||||
|
||||
public Result Result(string query, IPublicAPI api)
|
||||
{
|
||||
var score = Score(query);
|
||||
if (score <= 0)
|
||||
{ // no need to create result if score is 0
|
||||
var title = (Name, Description) switch
|
||||
{
|
||||
(var n, null) => n,
|
||||
(var n, var d) when d.Contains(n) => d,
|
||||
(var n, var d) when n.Contains(d) => n,
|
||||
(var n, var d) when !string.IsNullOrEmpty(d) => $"{n}: {d}",
|
||||
_ => Name
|
||||
};
|
||||
|
||||
var matchResult = StringMatcher.FuzzySearch(query, title);
|
||||
|
||||
if (!matchResult.Success)
|
||||
return null;
|
||||
}
|
||||
|
||||
var result = new Result
|
||||
{
|
||||
Title = title,
|
||||
SubTitle = Package.Location,
|
||||
Icon = Logo,
|
||||
Score = score,
|
||||
Score = matchResult.Score,
|
||||
TitleHighlightData = matchResult.MatchData,
|
||||
ContextData = this,
|
||||
Action = e =>
|
||||
{
|
||||
|
|
@ -294,23 +297,7 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
}
|
||||
};
|
||||
|
||||
if (Description.Length >= DisplayName.Length &&
|
||||
Description.Substring(0, DisplayName.Length) == DisplayName)
|
||||
{
|
||||
result.Title = Description;
|
||||
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Description).MatchData;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(Description))
|
||||
{
|
||||
var title = $"{DisplayName}: {Description}";
|
||||
result.Title = title;
|
||||
result.TitleHighlightData = StringMatcher.FuzzySearch(query, title).MatchData;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Title = DisplayName;
|
||||
result.TitleHighlightData = StringMatcher.FuzzySearch(query, DisplayName).MatchData;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,29 +33,30 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
private const string ApplicationReferenceExtension = "appref-ms";
|
||||
private const string ExeExtension = "exe";
|
||||
|
||||
private int Score(string query)
|
||||
{
|
||||
var nameMatch = StringMatcher.FuzzySearch(query, Name);
|
||||
var descriptionMatch = StringMatcher.FuzzySearch(query, Description);
|
||||
var executableNameMatch = StringMatcher.FuzzySearch(query, ExecutableName);
|
||||
var score = new[] { nameMatch.Score, descriptionMatch.Score, executableNameMatch.Score }.Max();
|
||||
return score;
|
||||
}
|
||||
|
||||
|
||||
public Result Result(string query, IPublicAPI api)
|
||||
{
|
||||
var score = Score(query);
|
||||
if (score <= 0)
|
||||
{ // no need to create result if this is zero
|
||||
var title = (Name, Description) switch
|
||||
{
|
||||
(var n, null) => n,
|
||||
(var n, var d) when d.Contains(n) => d,
|
||||
(var n, var d) when n.Contains(d) => n,
|
||||
(var n, var d) when !string.IsNullOrEmpty(d) => $"{n}: {d}",
|
||||
_ => Name
|
||||
};
|
||||
|
||||
var matchResult = StringMatcher.FuzzySearch(query, title);
|
||||
|
||||
if (!matchResult.Success)
|
||||
return null;
|
||||
}
|
||||
|
||||
var result = new Result
|
||||
{
|
||||
Title = title,
|
||||
SubTitle = FullPath,
|
||||
IcoPath = IcoPath,
|
||||
Score = score,
|
||||
Score = matchResult.Score,
|
||||
TitleHighlightData = matchResult.MatchData,
|
||||
ContextData = this,
|
||||
Action = e =>
|
||||
{
|
||||
|
|
@ -72,24 +73,6 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
}
|
||||
};
|
||||
|
||||
if (Description.Length >= Name.Length &&
|
||||
Description.Substring(0, Name.Length) == Name)
|
||||
{
|
||||
result.Title = Description;
|
||||
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Description).MatchData;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(Description))
|
||||
{
|
||||
var title = $"{Name}: {Description}";
|
||||
result.Title = title;
|
||||
result.TitleHighlightData = StringMatcher.FuzzySearch(query, title).MatchData;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Title = Name;
|
||||
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Name).MatchData;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue