@@ -22,9 +22,25 @@ public SearchManager(Settings settings, PluginInitContext context)
22
22
this . settings = settings ;
23
23
}
24
24
25
+ private class PathEqualityComparator : IEqualityComparer < Result >
26
+ {
27
+ private static PathEqualityComparator instance ;
28
+ public static PathEqualityComparator Instance => instance ??= new PathEqualityComparator ( ) ;
29
+ public bool Equals ( Result x , Result y )
30
+ {
31
+ return x . SubTitle == y . SubTitle ;
32
+ }
33
+
34
+ public int GetHashCode ( Result obj )
35
+ {
36
+ return obj . SubTitle . GetHashCode ( ) ;
37
+ }
38
+
39
+ }
40
+
25
41
internal async Task < List < Result > > SearchAsync ( Query query , CancellationToken token )
26
42
{
27
- var results = new List < Result > ( ) ;
43
+ var results = new HashSet < Result > ( PathEqualityComparator . Instance ) ;
28
44
29
45
var querySearch = query . Search ;
30
46
@@ -50,9 +66,9 @@ internal async Task<List<Result>> SearchAsync(Query query, CancellationToken tok
50
66
51
67
if ( ! querySearch . IsLocationPathString ( ) && ! isEnvironmentVariablePath )
52
68
{
53
- results . AddRange ( await WindowsIndexFilesAndFoldersSearchAsync ( query , querySearch , token ) . ConfigureAwait ( false ) ) ;
69
+ results . UnionWith ( await WindowsIndexFilesAndFoldersSearchAsync ( query , querySearch , token ) . ConfigureAwait ( false ) ) ;
54
70
55
- return results ;
71
+ return results . ToList ( ) ;
56
72
}
57
73
58
74
var locationPath = querySearch ;
@@ -62,7 +78,7 @@ internal async Task<List<Result>> SearchAsync(Query query, CancellationToken tok
62
78
63
79
// Check that actual location exists, otherwise directory search will throw directory not found exception
64
80
if ( ! FilesFolders . LocationExists ( FilesFolders . ReturnPreviousDirectoryIfIncompleteString ( locationPath ) ) )
65
- return results ;
81
+ return results . ToList ( ) ;
66
82
67
83
var useIndexSearch = UseWindowsIndexForDirectorySearch ( locationPath ) ;
68
84
@@ -79,9 +95,9 @@ internal async Task<List<Result>> SearchAsync(Query query, CancellationToken tok
79
95
80
96
token . ThrowIfCancellationRequested ( ) ;
81
97
82
- results . AddRange ( directoryResult ) ;
98
+ results . UnionWith ( directoryResult ) ;
83
99
84
- return results ;
100
+ return results . ToList ( ) ;
85
101
}
86
102
87
103
private async Task < List < Result > > WindowsIndexFileContentSearchAsync ( Query query , string querySearchString , CancellationToken token )
0 commit comments