@@ -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 ;
@@ -46,36 +47,39 @@ internal async Task<List<Result>> SearchAsync(Query query, CancellationToken tok
46
47
47
48
var result = new HashSet < Result > ( PathEqualityComparator . Instance ) ;
48
49
49
- if ( ActionKeywordMatch ( query , Settings . ActionKeyword . PathSearchActionKeyword ) || ActionKeywordMatch ( query , Settings . ActionKeyword . SearchActionKeyword ) )
50
+ if ( ActionKeywordMatch ( query , Settings . ActionKeyword . PathSearchActionKeyword ) ||
51
+ ActionKeywordMatch ( query , Settings . ActionKeyword . SearchActionKeyword ) )
50
52
{
51
53
result . UnionWith ( await PathSearchAsync ( query , token ) . ConfigureAwait ( false ) ) ;
52
54
}
53
55
54
- if ( ( ActionKeywordMatch ( query , Settings . ActionKeyword . IndexOnlySearchActionKeyword ) || ActionKeywordMatch ( query , Settings . ActionKeyword . SearchActionKeyword ) ) &&
55
- querySearch . Length > 0 &&
56
- ! querySearch . IsLocationPathString ( ) )
56
+ if ( ( ActionKeywordMatch ( query , Settings . ActionKeyword . IndexOnlySearchActionKeyword ) ||
57
+ ActionKeywordMatch ( query , Settings . ActionKeyword . SearchActionKeyword ) ) &&
58
+ querySearch . Length > 0 &&
59
+ ! querySearch . IsLocationPathString ( ) )
57
60
{
58
- result . UnionWith ( await WindowsIndexFilesAndFoldersSearchAsync ( query , querySearch , token ) . ConfigureAwait ( false ) ) ;
61
+ result . UnionWith ( await WindowsIndexFilesAndFoldersSearchAsync ( query , querySearch , token )
62
+ . ConfigureAwait ( false ) ) ;
59
63
}
60
64
61
65
return result . ToList ( ) ;
62
66
}
63
67
64
68
private bool ActionKeywordMatch ( Query query , Settings . ActionKeyword allowedActionKeyword )
65
69
{
66
- if ( query . ActionKeyword == settings . IndexOnlySearchActionKeyword )
67
- return Settings . ActionKeyword . IndexOnlySearchActionKeyword == allowedActionKeyword && settings . EnabledIndexOnlySearchKeyword ;
68
-
69
- if ( query . ActionKeyword == settings . PathSearchActionKeyword )
70
- return Settings . ActionKeyword . PathSearchActionKeyword == allowedActionKeyword && settings . EnabledPathSearchKeyword ;
70
+ var keyword = query . ActionKeyword . Length == 0 ? "*" : query . ActionKeyword ;
71
71
72
- if ( query . ActionKeyword == settings . SearchActionKeyword )
73
- return Settings . ActionKeyword . SearchActionKeyword == allowedActionKeyword ;
74
-
75
-
76
- return ( Settings . ActionKeyword . IndexOnlySearchActionKeyword == allowedActionKeyword && settings . EnabledIndexOnlySearchKeyword )
77
- || ( Settings . ActionKeyword . PathSearchActionKeyword == allowedActionKeyword && settings . EnabledPathSearchKeyword )
78
- || settings . SearchActionKeyword == Query . GlobalPluginWildcardSign ;
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 . IndexOnlySearchActionKeyword => settings . EnabledIndexOnlySearchKeyword &&
81
+ keyword == settings . IndexOnlySearchActionKeyword
82
+ } ;
79
83
}
80
84
81
85
public async Task < List < Result > > PathSearchAsync ( Query query , CancellationToken token = default )
@@ -129,19 +133,20 @@ public async Task<List<Result>> PathSearchAsync(Query query, CancellationToken t
129
133
return results . ToList ( ) ;
130
134
}
131
135
132
- 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 )
133
138
{
134
139
var queryConstructor = new QueryConstructor ( settings ) ;
135
140
136
141
if ( string . IsNullOrEmpty ( querySearchString ) )
137
142
return new List < Result > ( ) ;
138
143
139
144
return await IndexSearch . WindowsIndexSearchAsync ( querySearchString ,
140
- queryConstructor . CreateQueryHelper ( ) . ConnectionString ,
141
- queryConstructor . QueryForFileContentSearch ,
142
- settings . IndexSearchExcludedSubdirectoryPaths ,
143
- query ,
144
- token ) . ConfigureAwait ( false ) ;
145
+ queryConstructor . CreateQueryHelper ( ) . ConnectionString ,
146
+ queryConstructor . QueryForFileContentSearch ,
147
+ settings . IndexSearchExcludedSubdirectoryPaths ,
148
+ query ,
149
+ token ) . ConfigureAwait ( false ) ;
145
150
}
146
151
147
152
public bool IsFileContentSearch ( string actionKeyword )
@@ -168,28 +173,30 @@ public async Task<List<Result>> TopLevelDirectorySearchBehaviourAsync(
168
173
return await windowsIndexSearch ( query , querySearchString , token ) ;
169
174
}
170
175
171
- 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 )
172
178
{
173
179
var queryConstructor = new QueryConstructor ( settings ) ;
174
180
175
181
return await IndexSearch . WindowsIndexSearchAsync ( querySearchString ,
176
- queryConstructor . CreateQueryHelper ( ) . ConnectionString ,
177
- queryConstructor . QueryForAllFilesAndFolders ,
178
- settings . IndexSearchExcludedSubdirectoryPaths ,
179
- query ,
180
- token ) . ConfigureAwait ( false ) ;
182
+ queryConstructor . CreateQueryHelper ( ) . ConnectionString ,
183
+ queryConstructor . QueryForAllFilesAndFolders ,
184
+ settings . IndexSearchExcludedSubdirectoryPaths ,
185
+ query ,
186
+ token ) . ConfigureAwait ( false ) ;
181
187
}
182
188
183
- 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 )
184
191
{
185
192
var queryConstructor = new QueryConstructor ( settings ) ;
186
193
187
194
return await IndexSearch . WindowsIndexSearchAsync ( path ,
188
- queryConstructor . CreateQueryHelper ( ) . ConnectionString ,
189
- queryConstructor . QueryForTopLevelDirectorySearch ,
190
- settings . IndexSearchExcludedSubdirectoryPaths ,
191
- query ,
192
- token ) . ConfigureAwait ( false ) ;
195
+ queryConstructor . CreateQueryHelper ( ) . ConnectionString ,
196
+ queryConstructor . QueryForTopLevelDirectorySearch ,
197
+ settings . IndexSearchExcludedSubdirectoryPaths ,
198
+ query ,
199
+ token ) . ConfigureAwait ( false ) ;
193
200
}
194
201
195
202
private bool UseWindowsIndexForDirectorySearch ( string locationPath )
@@ -200,11 +207,11 @@ private bool UseWindowsIndexForDirectorySearch(string locationPath)
200
207
return false ;
201
208
202
209
if ( settings . IndexSearchExcludedSubdirectoryPaths
203
- . Any ( x => FilesFolders . ReturnPreviousDirectoryIfIncompleteString ( pathToDirectory )
204
- . StartsWith ( x . Path , StringComparison . OrdinalIgnoreCase ) ) )
210
+ . Any ( x => FilesFolders . ReturnPreviousDirectoryIfIncompleteString ( pathToDirectory )
211
+ . StartsWith ( x . Path , StringComparison . OrdinalIgnoreCase ) ) )
205
212
return false ;
206
213
207
214
return IndexSearch . PathIsIndexed ( pathToDirectory ) ;
208
215
}
209
216
}
210
- }
217
+ }
0 commit comments