Merge pull request #386 from Flow-Launcher/fix_windowsindex_exclude

Fix exclusion of Windows Index search for files and folders
This commit is contained in:
Jeremy Wu 2021-03-16 22:03:24 +11:00 committed by GitHub
commit 647e2b4ef8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 3 deletions

View file

@ -109,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);
}
@ -144,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);
}
@ -155,6 +157,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
return await IndexSearch.WindowsIndexSearchAsync(path,
queryConstructor.CreateQueryHelper().ConnectionString,
queryConstructor.QueryForTopLevelDirectorySearch,
settings.IndexSearchExcludedSubdirectoryPaths,
query,
token).ConfigureAwait(false);
}

View file

@ -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<List<Result>> WindowsIndexSearchAsync(string searchString, string connectionString,
Func<string, string> constructQuery, Query query,
Func<string, string> constructQuery,
List<AccessLink> 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<Result>();
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<List<Result>> RemoveResultsInExclusionList(List<Result> results, List<AccessLink> exclusionList)
{
var indexExclusionListCount = exclusionList.Count;
if (indexExclusionListCount == 0)
return results;
var filteredResults = new List<Result>();
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)

View file

@ -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",