diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index a1fc6f6ed..e9b4b0fc1 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -65,10 +65,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search if (!querySearch.IsLocationPathString() && !isEnvironmentVariablePath) { - var filteredResults = FilterOutResultsFromWindowsIndexExclusionList( - await WindowsIndexFilesAndFoldersSearchAsync(query, querySearch, token).ConfigureAwait(false)); - - results.UnionWith(filteredResults); + results.UnionWith(await WindowsIndexFilesAndFoldersSearchAsync(query, querySearch, token).ConfigureAwait(false)); return results.ToList(); } @@ -112,6 +109,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search return await IndexSearch.WindowsIndexSearchAsync(querySearchString, queryConstructor.CreateQueryHelper().ConnectionString, queryConstructor.QueryForFileContentSearch, + settings.IndexSearchExcludedSubdirectoryPaths, query, token).ConfigureAwait(false); } @@ -147,6 +145,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search return await IndexSearch.WindowsIndexSearchAsync(querySearchString, queryConstructor.CreateQueryHelper().ConnectionString, queryConstructor.QueryForAllFilesAndFolders, + settings.IndexSearchExcludedSubdirectoryPaths, query, token).ConfigureAwait(false); } @@ -158,41 +157,11 @@ namespace Flow.Launcher.Plugin.Explorer.Search return await IndexSearch.WindowsIndexSearchAsync(path, queryConstructor.CreateQueryHelper().ConnectionString, queryConstructor.QueryForTopLevelDirectorySearch, + settings.IndexSearchExcludedSubdirectoryPaths, query, token).ConfigureAwait(false); } - private HashSet FilterOutResultsFromWindowsIndexExclusionList(List results) - { - var indexExclusionList = settings.IndexSearchExcludedSubdirectoryPaths; - - var indexExclusionListCount = indexExclusionList.Count; - - if (indexExclusionListCount == 0) - return results.ToHashSet(); - - var filteredResults = new HashSet(PathEqualityComparator.Instance); - - for (var index = 0; index < results.Count; index++) - { - var excludeResult = false; - - for (var i = 0; i < indexExclusionListCount; i++) - { - if (results[index].SubTitle.StartsWith(indexExclusionList[i].Path, StringComparison.OrdinalIgnoreCase)) - { - excludeResult = true; - break; - } - } - - if (!excludeResult) - filteredResults.Add(results[index]); - } - - return filteredResults; - } - private bool UseWindowsIndexForDirectorySearch(string locationPath) { var pathToDirectory = FilesFolders.ReturnPreviousDirectoryIfIncompleteString(locationPath); diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearch.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearch.cs index b1e1d7622..ecadd61ec 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearch.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearch.cs @@ -1,4 +1,5 @@ using Flow.Launcher.Infrastructure.Logger; +using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks; using Microsoft.Search.Interop; using System; using System.Collections.Generic; @@ -83,7 +84,9 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex } internal async static Task> WindowsIndexSearchAsync(string searchString, string connectionString, - Func constructQuery, Query query, + Func constructQuery, + List exclusionList, + Query query, CancellationToken token) { var regexMatch = Regex.Match(searchString, reservedStringPattern); @@ -92,8 +95,41 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex return new List(); var constructedQuery = constructQuery(searchString); - return await ExecuteWindowsIndexSearchAsync(constructedQuery, connectionString, query, token); + return await RemoveResultsInExclusionList( + await ExecuteWindowsIndexSearchAsync(constructedQuery, connectionString, query, token), + exclusionList); + } + private async static Task> RemoveResultsInExclusionList(List results, List exclusionList) + { + var indexExclusionListCount = exclusionList.Count; + + if (indexExclusionListCount == 0) + return results; + + var filteredResults = new List(); + + await Task.Run(() => + { + for (var index = 0; index < results.Count; index++) + { + var excludeResult = false; + + for (var i = 0; i < indexExclusionListCount; i++) + { + if (results[index].SubTitle.StartsWith(exclusionList[i].Path, StringComparison.OrdinalIgnoreCase)) + { + excludeResult = true; + break; + } + } + + if (!excludeResult) + filteredResults.Add(results[index]); + } + }); + + return filteredResults; } internal static bool PathIsIndexed(string path)