From 43f1cae35020de48a7b46f2e13a916c52462327d Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Mon, 15 Mar 2021 06:01:29 +1100 Subject: [PATCH 1/6] fix exclusion of Windows Index file or folder search --- .../Search/SearchManager.cs | 25 ++++++++++++++++++- .../Flow.Launcher.Plugin.Explorer/plugin.json | 2 +- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index d5f882d5c..15ffa19c4 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -67,7 +67,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search { results.UnionWith(await WindowsIndexFilesAndFoldersSearchAsync(query, querySearch, token).ConfigureAwait(false)); - return results.ToList(); + return FilterOutResultsFromWindowsIndexExclusionList(results).ToList(); } var locationPath = querySearch; @@ -159,6 +159,29 @@ namespace Flow.Launcher.Plugin.Explorer.Search token).ConfigureAwait(false); } + private HashSet FilterOutResultsFromWindowsIndexExclusionList(HashSet results) + { + var indexExclusionList = settings.IndexSearchExcludedSubdirectoryPaths; + + var indexExclusionListCount = indexExclusionList.Count; + + if (indexExclusionListCount == 0) + return results; + + var filteredResults = new HashSet(PathEqualityComparator.Instance); + + foreach (var r in results) + { + for (var i = 0; i < indexExclusionListCount; i++) + { + if (!r.SubTitle.StartsWith(indexExclusionList[0].Path, StringComparison.OrdinalIgnoreCase)) + filteredResults.Add(r); + } + } + + return filteredResults; + } + private bool UseWindowsIndexForDirectorySearch(string locationPath) { var pathToDirectory = FilesFolders.ReturnPreviousDirectoryIfIncompleteString(locationPath); diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json b/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json index 63ca66a1e..990ceadda 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json +++ b/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json @@ -7,7 +7,7 @@ "Name": "Explorer", "Description": "Search and manage files and folders. Explorer utilises Windows Index Search", "Author": "Jeremy Wu", - "Version": "1.7.1", + "Version": "1.7.2", "Language": "csharp", "Website": "https://github.com/Flow-Launcher/Flow.Launcher", "ExecuteFileName": "Flow.Launcher.Plugin.Explorer.dll", From a5e3049adcfc71f1f39ce56375e881839b406c34 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Mon, 15 Mar 2021 07:39:14 +1100 Subject: [PATCH 2/6] fix typo --- Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index 15ffa19c4..f719a22d9 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -174,7 +174,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search { for (var i = 0; i < indexExclusionListCount; i++) { - if (!r.SubTitle.StartsWith(indexExclusionList[0].Path, StringComparison.OrdinalIgnoreCase)) + if (!r.SubTitle.StartsWith(indexExclusionList[i].Path, StringComparison.OrdinalIgnoreCase)) filteredResults.Add(r); } } From b642898132095b4cc3294a82eaefb42127ac41cb Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Mon, 15 Mar 2021 08:12:03 +1100 Subject: [PATCH 3/6] update loop logic --- .../Search/SearchManager.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index f719a22d9..2983c7d35 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -172,11 +172,19 @@ namespace Flow.Launcher.Plugin.Explorer.Search foreach (var r in results) { + var excludeResult = false; + for (var i = 0; i < indexExclusionListCount; i++) { - if (!r.SubTitle.StartsWith(indexExclusionList[i].Path, StringComparison.OrdinalIgnoreCase)) - filteredResults.Add(r); + if (r.SubTitle.StartsWith(indexExclusionList[i].Path, StringComparison.OrdinalIgnoreCase)) + { + excludeResult = true; + break; + } } + + if (!excludeResult) + filteredResults.Add(r); } return filteredResults; From b2dc2ef71b768e402ab685e8883dccdd8b6c243b Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Tue, 16 Mar 2021 07:12:01 +1100 Subject: [PATCH 4/6] do not exclude if in Quick Access list --- .../Search/SearchManager.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index 2983c7d35..e78324718 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -1,4 +1,4 @@ -using Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo; +using Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo; using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks; using Flow.Launcher.Plugin.Explorer.Search.WindowsIndex; using Flow.Launcher.Plugin.SharedCommands; @@ -65,9 +65,12 @@ namespace Flow.Launcher.Plugin.Explorer.Search if (!querySearch.IsLocationPathString() && !isEnvironmentVariablePath) { - results.UnionWith(await WindowsIndexFilesAndFoldersSearchAsync(query, querySearch, token).ConfigureAwait(false)); + var filteredResults = FilterOutResultsFromWindowsIndexExclusionList( + await WindowsIndexFilesAndFoldersSearchAsync(query, querySearch, token).ConfigureAwait(false)); - return FilterOutResultsFromWindowsIndexExclusionList(results).ToList(); + results.UnionWith(filteredResults); + + return results.ToList(); } var locationPath = querySearch; From e73b2a05ce14acc3513a6293581655322599892f Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Tue, 16 Mar 2021 07:12:36 +1100 Subject: [PATCH 5/6] change to for loop --- .../Search/SearchManager.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index e78324718..a1fc6f6ed 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -1,4 +1,4 @@ -using Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo; +using Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo; using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks; using Flow.Launcher.Plugin.Explorer.Search.WindowsIndex; using Flow.Launcher.Plugin.SharedCommands; @@ -162,24 +162,24 @@ namespace Flow.Launcher.Plugin.Explorer.Search token).ConfigureAwait(false); } - private HashSet FilterOutResultsFromWindowsIndexExclusionList(HashSet results) + private HashSet FilterOutResultsFromWindowsIndexExclusionList(List results) { var indexExclusionList = settings.IndexSearchExcludedSubdirectoryPaths; var indexExclusionListCount = indexExclusionList.Count; if (indexExclusionListCount == 0) - return results; + return results.ToHashSet(); var filteredResults = new HashSet(PathEqualityComparator.Instance); - foreach (var r in results) + for (var index = 0; index < results.Count; index++) { var excludeResult = false; for (var i = 0; i < indexExclusionListCount; i++) { - if (r.SubTitle.StartsWith(indexExclusionList[i].Path, StringComparison.OrdinalIgnoreCase)) + if (results[index].SubTitle.StartsWith(indexExclusionList[i].Path, StringComparison.OrdinalIgnoreCase)) { excludeResult = true; break; @@ -187,7 +187,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search } if (!excludeResult) - filteredResults.Add(r); + filteredResults.Add(results[index]); } return filteredResults; From 7aa1396821f6951ae365d4cc53790d938918e174 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Tue, 16 Mar 2021 21:33:40 +1100 Subject: [PATCH 6/6] move index exclude method to IndexSearch class and add async --- .../Search/SearchManager.cs | 39 ++---------------- .../Search/WindowsIndex/IndexSearch.cs | 40 ++++++++++++++++++- 2 files changed, 42 insertions(+), 37 deletions(-) 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)