Skip to content

Commit 04ee651

Browse files
taoocerosbao-qian
andcommitted
remove extra fuzzy search
Co-authored-by: Qian Bao <[email protected]>
1 parent 86edae2 commit 04ee651

File tree

2 files changed

+31
-61
lines changed

2 files changed

+31
-61
lines changed

Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -265,27 +265,30 @@ public class Application : IProgram
265265

266266
public Application(){}
267267

268-
private int Score(string query)
269-
{
270-
var displayNameMatch = StringMatcher.FuzzySearch(query, DisplayName);
271-
var descriptionMatch = StringMatcher.FuzzySearch(query, Description);
272-
var score = new[] { displayNameMatch.Score, descriptionMatch.Score }.Max();
273-
return score;
274-
}
275268

276269
public Result Result(string query, IPublicAPI api)
277270
{
278-
var score = Score(query);
279-
if (score <= 0)
280-
{ // no need to create result if score is 0
271+
var title = (Name, Description) switch
272+
{
273+
(var n, null) => n,
274+
(var n, var d) when d.Contains(n) => d,
275+
(var n, var d) when n.Contains(d) => n,
276+
(var n, var d) when !string.IsNullOrEmpty(d) => $"{n}: {d}",
277+
_ => Name
278+
};
279+
280+
var matchResult = StringMatcher.FuzzySearch(query, title);
281+
282+
if (!matchResult.Success)
281283
return null;
282-
}
283284

284285
var result = new Result
285286
{
287+
Title = title,
286288
SubTitle = Package.Location,
287289
Icon = Logo,
288-
Score = score,
290+
Score = matchResult.Score,
291+
TitleHighlightData = matchResult.MatchData,
289292
ContextData = this,
290293
Action = e =>
291294
{
@@ -294,23 +297,7 @@ public Result Result(string query, IPublicAPI api)
294297
}
295298
};
296299

297-
if (Description.Length >= DisplayName.Length &&
298-
Description.Substring(0, DisplayName.Length) == DisplayName)
299-
{
300-
result.Title = Description;
301-
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Description).MatchData;
302-
}
303-
else if (!string.IsNullOrEmpty(Description))
304-
{
305-
var title = $"{DisplayName}: {Description}";
306-
result.Title = title;
307-
result.TitleHighlightData = StringMatcher.FuzzySearch(query, title).MatchData;
308-
}
309-
else
310-
{
311-
result.Title = DisplayName;
312-
result.TitleHighlightData = StringMatcher.FuzzySearch(query, DisplayName).MatchData;
313-
}
300+
314301
return result;
315302
}
316303

Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,30 @@ public class Win32 : IProgram
3333
private const string ApplicationReferenceExtension = "appref-ms";
3434
private const string ExeExtension = "exe";
3535

36-
private int Score(string query)
37-
{
38-
var nameMatch = StringMatcher.FuzzySearch(query, Name);
39-
var descriptionMatch = StringMatcher.FuzzySearch(query, Description);
40-
var executableNameMatch = StringMatcher.FuzzySearch(query, ExecutableName);
41-
var score = new[] { nameMatch.Score, descriptionMatch.Score, executableNameMatch.Score }.Max();
42-
return score;
43-
}
44-
4536

4637
public Result Result(string query, IPublicAPI api)
4738
{
48-
var score = Score(query);
49-
if (score <= 0)
50-
{ // no need to create result if this is zero
39+
var title = (Name, Description) switch
40+
{
41+
(var n, null) => n,
42+
(var n, var d) when d.Contains(n) => d,
43+
(var n, var d) when n.Contains(d) => n,
44+
(var n, var d) when !string.IsNullOrEmpty(d) => $"{n}: {d}",
45+
_ => Name
46+
};
47+
48+
var matchResult = StringMatcher.FuzzySearch(query, title);
49+
50+
if (!matchResult.Success)
5151
return null;
52-
}
5352

5453
var result = new Result
5554
{
55+
Title = title,
5656
SubTitle = FullPath,
5757
IcoPath = IcoPath,
58-
Score = score,
58+
Score = matchResult.Score,
59+
TitleHighlightData = matchResult.MatchData,
5960
ContextData = this,
6061
Action = e =>
6162
{
@@ -72,24 +73,6 @@ public Result Result(string query, IPublicAPI api)
7273
}
7374
};
7475

75-
if (Description.Length >= Name.Length &&
76-
Description.Substring(0, Name.Length) == Name)
77-
{
78-
result.Title = Description;
79-
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Description).MatchData;
80-
}
81-
else if (!string.IsNullOrEmpty(Description))
82-
{
83-
var title = $"{Name}: {Description}";
84-
result.Title = title;
85-
result.TitleHighlightData = StringMatcher.FuzzySearch(query, title).MatchData;
86-
}
87-
else
88-
{
89-
result.Title = Name;
90-
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Name).MatchData;
91-
}
92-
9376
return result;
9477
}
9578

0 commit comments

Comments
 (0)