@@ -26,6 +26,7 @@ private class PathEqualityComparator : IEqualityComparer<Result>
26
26
{
27
27
private static PathEqualityComparator instance ;
28
28
public static PathEqualityComparator Instance => instance ??= new PathEqualityComparator ( ) ;
29
+
29
30
public bool Equals ( Result x , Result y )
30
31
{
31
32
return x . SubTitle == y . SubTitle ;
@@ -39,21 +40,61 @@ public int GetHashCode(Result obj)
39
40
40
41
internal async Task < List < Result > > SearchAsync ( Query query , CancellationToken token )
41
42
{
42
- var results = new HashSet < Result > ( PathEqualityComparator . Instance ) ;
43
-
44
43
var querySearch = query . Search ;
45
44
46
45
if ( IsFileContentSearch ( query . ActionKeyword ) )
47
46
return await WindowsIndexFileContentSearchAsync ( query , querySearch , token ) . ConfigureAwait ( false ) ;
48
47
48
+ var result = new HashSet < Result > ( PathEqualityComparator . Instance ) ;
49
+
50
+ if ( ActionKeywordMatch ( query , Settings . ActionKeyword . PathSearchActionKeyword ) ||
51
+ ActionKeywordMatch ( query , Settings . ActionKeyword . SearchActionKeyword ) )
52
+ {
53
+ result . UnionWith ( await PathSearchAsync ( query , token ) . ConfigureAwait ( false ) ) ;
54
+ }
55
+
56
+ if ( ( ActionKeywordMatch ( query , Settings . ActionKeyword . IndexSearchActionKeyword ) ||
57
+ ActionKeywordMatch ( query , Settings . ActionKeyword . SearchActionKeyword ) ) &&
58
+ querySearch . Length > 0 &&
59
+ ! querySearch . IsLocationPathString ( ) )
60
+ {
61
+ result . UnionWith ( await WindowsIndexFilesAndFoldersSearchAsync ( query , querySearch , token )
62
+ . ConfigureAwait ( false ) ) ;
63
+ }
64
+
65
+ return result . ToList ( ) ;
66
+ }
67
+
68
+ private bool ActionKeywordMatch ( Query query , Settings . ActionKeyword allowedActionKeyword )
69
+ {
70
+ var keyword = query . ActionKeyword . Length == 0 ? Query . GlobalPluginWildcardSign : query . ActionKeyword ;
71
+
72
+ return allowedActionKeyword switch
73
+ {
74
+ Settings . ActionKeyword . SearchActionKeyword => settings . EnableSearchActionKeyword &&
75
+ keyword == settings . SearchActionKeyword ,
76
+ Settings . ActionKeyword . PathSearchActionKeyword => settings . EnabledPathSearchKeyword &&
77
+ keyword == settings . PathSearchActionKeyword ,
78
+ Settings . ActionKeyword . FileContentSearchActionKeyword => keyword ==
79
+ settings . FileContentSearchActionKeyword ,
80
+ Settings . ActionKeyword . IndexSearchActionKeyword => settings . EnabledIndexOnlySearchKeyword &&
81
+ keyword == settings . IndexSearchActionKeyword
82
+ } ;
83
+ }
84
+
85
+ public async Task < List < Result > > PathSearchAsync ( Query query , CancellationToken token = default )
86
+ {
87
+ var querySearch = query . Search ;
88
+
49
89
// This allows the user to type the assigned action keyword and only see the list of quick folder links
50
90
if ( string . IsNullOrEmpty ( query . Search ) )
51
91
return QuickAccess . AccessLinkListAll ( query , settings . QuickAccessLinks ) ;
52
92
93
+ var results = new HashSet < Result > ( PathEqualityComparator . Instance ) ;
94
+
53
95
var quickaccessLinks = QuickAccess . AccessLinkListMatched ( query , settings . QuickAccessLinks ) ;
54
96
55
- if ( quickaccessLinks . Count > 0 )
56
- results . UnionWith ( quickaccessLinks ) ;
97
+ results . UnionWith ( quickaccessLinks ) ;
57
98
58
99
var isEnvironmentVariable = EnvironmentVariables . IsEnvironmentVariableSearch ( querySearch ) ;
59
100
@@ -63,13 +104,6 @@ internal async Task<List<Result>> SearchAsync(Query query, CancellationToken tok
63
104
// Query is a location path with a full environment variable, eg. %appdata%\somefolder\
64
105
var isEnvironmentVariablePath = querySearch [ 1 ..] . Contains ( "%\\ " ) ;
65
106
66
- if ( ! querySearch . IsLocationPathString ( ) && ! isEnvironmentVariablePath )
67
- {
68
- results . UnionWith ( await WindowsIndexFilesAndFoldersSearchAsync ( query , querySearch , token ) . ConfigureAwait ( false ) ) ;
69
-
70
- return results . ToList ( ) ;
71
- }
72
-
73
107
var locationPath = querySearch ;
74
108
75
109
if ( isEnvironmentVariablePath )
@@ -99,19 +133,20 @@ internal async Task<List<Result>> SearchAsync(Query query, CancellationToken tok
99
133
return results . ToList ( ) ;
100
134
}
101
135
102
- private async Task < List < Result > > WindowsIndexFileContentSearchAsync ( Query query , string querySearchString , CancellationToken token )
136
+ private async Task < List < Result > > WindowsIndexFileContentSearchAsync ( Query query , string querySearchString ,
137
+ CancellationToken token )
103
138
{
104
139
var queryConstructor = new QueryConstructor ( settings ) ;
105
140
106
141
if ( string . IsNullOrEmpty ( querySearchString ) )
107
142
return new List < Result > ( ) ;
108
143
109
144
return await IndexSearch . WindowsIndexSearchAsync ( querySearchString ,
110
- queryConstructor . CreateQueryHelper ( ) . ConnectionString ,
111
- queryConstructor . QueryForFileContentSearch ,
112
- settings . IndexSearchExcludedSubdirectoryPaths ,
113
- query ,
114
- token ) . ConfigureAwait ( false ) ;
145
+ queryConstructor . CreateQueryHelper ( ) . ConnectionString ,
146
+ queryConstructor . QueryForFileContentSearch ,
147
+ settings . IndexSearchExcludedSubdirectoryPaths ,
148
+ query ,
149
+ token ) . ConfigureAwait ( false ) ;
115
150
}
116
151
117
152
public bool IsFileContentSearch ( string actionKeyword )
@@ -138,28 +173,30 @@ public async Task<List<Result>> TopLevelDirectorySearchBehaviourAsync(
138
173
return await windowsIndexSearch ( query , querySearchString , token ) ;
139
174
}
140
175
141
- private async Task < List < Result > > WindowsIndexFilesAndFoldersSearchAsync ( Query query , string querySearchString , CancellationToken token )
176
+ private async Task < List < Result > > WindowsIndexFilesAndFoldersSearchAsync ( Query query , string querySearchString ,
177
+ CancellationToken token )
142
178
{
143
179
var queryConstructor = new QueryConstructor ( settings ) ;
144
180
145
181
return await IndexSearch . WindowsIndexSearchAsync ( querySearchString ,
146
- queryConstructor . CreateQueryHelper ( ) . ConnectionString ,
147
- queryConstructor . QueryForAllFilesAndFolders ,
148
- settings . IndexSearchExcludedSubdirectoryPaths ,
149
- query ,
150
- token ) . ConfigureAwait ( false ) ;
182
+ queryConstructor . CreateQueryHelper ( ) . ConnectionString ,
183
+ queryConstructor . QueryForAllFilesAndFolders ,
184
+ settings . IndexSearchExcludedSubdirectoryPaths ,
185
+ query ,
186
+ token ) . ConfigureAwait ( false ) ;
151
187
}
152
188
153
- private async Task < List < Result > > WindowsIndexTopLevelFolderSearchAsync ( Query query , string path , CancellationToken token )
189
+ private async Task < List < Result > > WindowsIndexTopLevelFolderSearchAsync ( Query query , string path ,
190
+ CancellationToken token )
154
191
{
155
192
var queryConstructor = new QueryConstructor ( settings ) ;
156
193
157
194
return await IndexSearch . WindowsIndexSearchAsync ( path ,
158
- queryConstructor . CreateQueryHelper ( ) . ConnectionString ,
159
- queryConstructor . QueryForTopLevelDirectorySearch ,
160
- settings . IndexSearchExcludedSubdirectoryPaths ,
161
- query ,
162
- token ) . ConfigureAwait ( false ) ;
195
+ queryConstructor . CreateQueryHelper ( ) . ConnectionString ,
196
+ queryConstructor . QueryForTopLevelDirectorySearch ,
197
+ settings . IndexSearchExcludedSubdirectoryPaths ,
198
+ query ,
199
+ token ) . ConfigureAwait ( false ) ;
163
200
}
164
201
165
202
private bool UseWindowsIndexForDirectorySearch ( string locationPath )
@@ -170,11 +207,11 @@ private bool UseWindowsIndexForDirectorySearch(string locationPath)
170
207
return false ;
171
208
172
209
if ( settings . IndexSearchExcludedSubdirectoryPaths
173
- . Any ( x => FilesFolders . ReturnPreviousDirectoryIfIncompleteString ( pathToDirectory )
174
- . StartsWith ( x . Path , StringComparison . OrdinalIgnoreCase ) ) )
210
+ . Any ( x => FilesFolders . ReturnPreviousDirectoryIfIncompleteString ( pathToDirectory )
211
+ . StartsWith ( x . Path , StringComparison . OrdinalIgnoreCase ) ) )
175
212
return false ;
176
213
177
214
return IndexSearch . PathIsIndexed ( pathToDirectory ) ;
178
215
}
179
216
}
180
- }
217
+ }
0 commit comments