Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Flow.Launcher.Infrastructure/StringMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption
return new MatchResult(false, UserSettingSearchPrecision);
}

private bool IsAcronym(string stringToCompare, int compareStringIndex)
private static bool IsAcronym(string stringToCompare, int compareStringIndex)
{
if (IsAcronymChar(stringToCompare, compareStringIndex) || IsAcronymNumber(stringToCompare, compareStringIndex))
return true;
Expand All @@ -237,7 +237,7 @@ private bool IsAcronym(string stringToCompare, int compareStringIndex)
}

// When counting acronyms, treat a set of numbers as one acronym ie. Visual 2019 as 2 acronyms instead of 5
private bool IsAcronymCount(string stringToCompare, int compareStringIndex)
private static bool IsAcronymCount(string stringToCompare, int compareStringIndex)
{
if (IsAcronymChar(stringToCompare, compareStringIndex))
return true;
Expand Down
7 changes: 7 additions & 0 deletions Flow.Launcher.Plugin/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@ public ValueTask<bool> ExecuteAsync(ActionContext context)
/// </summary>
public string RecordKey { get; set; } = null;

/// <summary>
/// The key to be compared with the user input for fuzzy search.
/// This can be useful when the plugin wants to provide a different string for fuzzy search.
/// If the plugin does not specific this, FL just uses Title and SubTitle to compare with the user input.
/// </summary>
public string StringMatcherKey { get; set; }

/// <summary>
/// Info of the preview section of a <see cref="Result"/>
/// </summary>
Expand Down
23 changes: 18 additions & 5 deletions Flow.Launcher/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using Flow.Launcher.Infrastructure.Image;
using System.Windows.Media;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Plugin.SharedModels;

namespace Flow.Launcher.ViewModel
{
Expand Down Expand Up @@ -1016,10 +1017,20 @@ private void QueryContextMenu()
(
r =>
{
var match = StringMatcher.FuzzySearch(query, r.Title);
if (!match.IsSearchPrecisionScoreMet())
MatchResult match;
if (!string.IsNullOrEmpty(r.StringMatcherKey))
{
match = StringMatcher.FuzzySearch(query, r.SubTitle);
match = StringMatcher.FuzzySearch(query, r.StringMatcherKey);
// If StringMatcherKey is not met, we should not check Title and SubTitle because
// developers have set the StringMatcherKey to be the only searchable field
}
else
{
match = StringMatcher.FuzzySearch(query, r.Title);
if (!match.IsSearchPrecisionScoreMet())
{
match = StringMatcher.FuzzySearch(query, r.SubTitle);
}
}

if (!match.IsSearchPrecisionScoreMet()) return false;
Expand Down Expand Up @@ -1067,8 +1078,10 @@ private void QueryHistory()
{
var filtered = results.Where
(
r => StringMatcher.FuzzySearch(query, r.Title).IsSearchPrecisionScoreMet() ||
StringMatcher.FuzzySearch(query, r.SubTitle).IsSearchPrecisionScoreMet()
r => (!string.IsNullOrEmpty(r.StringMatcherKey)) ?
StringMatcher.FuzzySearch(query, r.StringMatcherKey).IsSearchPrecisionScoreMet() :
StringMatcher.FuzzySearch(query, r.Title).IsSearchPrecisionScoreMet() ||
StringMatcher.FuzzySearch(query, r.SubTitle).IsSearchPrecisionScoreMet()
).ToList();
History.AddResults(filtered, id);
}
Expand Down
Loading