mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Use Hashset and customized equality comparator to filter result
This commit is contained in:
parent
6543e4f335
commit
32435bcda5
1 changed files with 22 additions and 6 deletions
|
|
@ -22,9 +22,25 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
this.settings = settings;
|
||||
}
|
||||
|
||||
private class PathEqualityComparator : IEqualityComparer<Result>
|
||||
{
|
||||
private static PathEqualityComparator instance;
|
||||
public static PathEqualityComparator Instance => instance ??= new PathEqualityComparator();
|
||||
public bool Equals(Result x, Result y)
|
||||
{
|
||||
return x.SubTitle == y.SubTitle;
|
||||
}
|
||||
|
||||
public int GetHashCode(Result obj)
|
||||
{
|
||||
return obj.SubTitle.GetHashCode();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal async Task<List<Result>> SearchAsync(Query query, CancellationToken token)
|
||||
{
|
||||
var results = new List<Result>();
|
||||
var results = new HashSet<Result>(PathEqualityComparator.Instance);
|
||||
|
||||
var querySearch = query.Search;
|
||||
|
||||
|
|
@ -50,9 +66,9 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
|
||||
if (!querySearch.IsLocationPathString() && !isEnvironmentVariablePath)
|
||||
{
|
||||
results.AddRange(await WindowsIndexFilesAndFoldersSearchAsync(query, querySearch, token).ConfigureAwait(false));
|
||||
results.UnionWith(await WindowsIndexFilesAndFoldersSearchAsync(query, querySearch, token).ConfigureAwait(false));
|
||||
|
||||
return results;
|
||||
return results.ToList();
|
||||
}
|
||||
|
||||
var locationPath = querySearch;
|
||||
|
|
@ -62,7 +78,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
|
||||
// Check that actual location exists, otherwise directory search will throw directory not found exception
|
||||
if (!FilesFolders.LocationExists(FilesFolders.ReturnPreviousDirectoryIfIncompleteString(locationPath)))
|
||||
return results;
|
||||
return results.ToList();
|
||||
|
||||
var useIndexSearch = UseWindowsIndexForDirectorySearch(locationPath);
|
||||
|
||||
|
|
@ -79,9 +95,9 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
results.AddRange(directoryResult);
|
||||
results.UnionWith(directoryResult);
|
||||
|
||||
return results;
|
||||
return results.ToList();
|
||||
}
|
||||
|
||||
private async Task<List<Result>> WindowsIndexFileContentSearchAsync(Query query, string querySearchString, CancellationToken token)
|
||||
|
|
|
|||
Loading…
Reference in a new issue