Skip to content

[Explorer] Only files and only folders search #571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
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
16 changes: 16 additions & 0 deletions Flow.Launcher.Core/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,22 @@ public static async Task InitializePlugins(IPublicAPI api)
NonGlobalPlugins[actionKeyword] = plugin;
break;
}






if (plugin.Metadata.Name == "Explorer")
{
NonGlobalPlugins["d"] = plugin;
NonGlobalPlugins["f"] = plugin;
}





}
}

Expand Down
44 changes: 44 additions & 0 deletions Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Text.RegularExpressions;

namespace Flow.Launcher.Plugin.Explorer.Search
{
Expand Down Expand Up @@ -41,6 +42,49 @@ public int GetHashCode(Result obj)
internal async Task<List<Result>> SearchAsync(Query query, CancellationToken token)
{
var querySearch = query.Search;





if ((query.ActionKeyword == "d" || query.ActionKeyword == "f") && querySearch.Length > 0)
{
var queryConstructor = new QueryConstructor(settings);

var connectionString = queryConstructor.CreateQueryHelper().ConnectionString;
var reservedStringPattern = @"^[`\@\#\^,\&\/\\\$\%_]+$";


var regexMatch = Regex.Match(querySearch, reservedStringPattern);

if (regexMatch.Success)
return new List<Result>();

var constructedQuery = $@"SELECT TOP 100
System.FileName,
System.ItemUrl,
System.ItemType,
System.Search.Rank
FROM SystemIndex
WHERE scope='file:'
AND CONTAINS(System.FileName,'""{querySearch}*""', 2057)";
if (query.ActionKeyword == "d")
{
constructedQuery += " AND System.ItemType = 'Directory' ";
} else if (query.ActionKeyword == "f")
{
constructedQuery += " AND NOT System.ItemType = 'Directory' ";
}
constructedQuery += " ORDER BY System.Search.Rank DESC ";

return await IndexSearch.ExecuteWindowsIndexSearchAsync(constructedQuery, connectionString, query, token)
.ConfigureAwait(false);
}






if (IsFileContentSearch(query.ActionKeyword))
return await WindowsIndexFileContentSearchAsync(query, querySearch, token).ConfigureAwait(false);
Expand Down