@@ -26,6 +26,7 @@ private class PathEqualityComparator : IEqualityComparer<Result>
2626 {
2727 private static PathEqualityComparator instance ;
2828 public static PathEqualityComparator Instance => instance ??= new PathEqualityComparator ( ) ;
29+
2930 public bool Equals ( Result x , Result y )
3031 {
3132 return x . SubTitle == y . SubTitle ;
@@ -39,21 +40,61 @@ public int GetHashCode(Result obj)
3940
4041 internal async Task < List < Result > > SearchAsync ( Query query , CancellationToken token )
4142 {
42- var results = new HashSet < Result > ( PathEqualityComparator . Instance ) ;
43-
4443 var querySearch = query . Search ;
4544
4645 if ( IsFileContentSearch ( query . ActionKeyword ) )
4746 return await WindowsIndexFileContentSearchAsync ( query , querySearch , token ) . ConfigureAwait ( false ) ;
4847
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+
4989 // This allows the user to type the assigned action keyword and only see the list of quick folder links
5090 if ( string . IsNullOrEmpty ( query . Search ) )
5191 return QuickAccess . AccessLinkListAll ( query , settings . QuickAccessLinks ) ;
5292
93+ var results = new HashSet < Result > ( PathEqualityComparator . Instance ) ;
94+
5395 var quickaccessLinks = QuickAccess . AccessLinkListMatched ( query , settings . QuickAccessLinks ) ;
5496
55- if ( quickaccessLinks . Count > 0 )
56- results . UnionWith ( quickaccessLinks ) ;
97+ results . UnionWith ( quickaccessLinks ) ;
5798
5899 var isEnvironmentVariable = EnvironmentVariables . IsEnvironmentVariableSearch ( querySearch ) ;
59100
@@ -63,13 +104,6 @@ internal async Task<List<Result>> SearchAsync(Query query, CancellationToken tok
63104 // Query is a location path with a full environment variable, eg. %appdata%\somefolder\
64105 var isEnvironmentVariablePath = querySearch [ 1 ..] . Contains ( "%\\ " ) ;
65106
66- if ( ! querySearch . IsLocationPathString ( ) && ! isEnvironmentVariablePath )
67- {
68- results . UnionWith ( await WindowsIndexFilesAndFoldersSearchAsync ( query , querySearch , token ) . ConfigureAwait ( false ) ) ;
69-
70- return results . ToList ( ) ;
71- }
72-
73107 var locationPath = querySearch ;
74108
75109 if ( isEnvironmentVariablePath )
@@ -99,19 +133,20 @@ internal async Task<List<Result>> SearchAsync(Query query, CancellationToken tok
99133 return results . ToList ( ) ;
100134 }
101135
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 )
103138 {
104139 var queryConstructor = new QueryConstructor ( settings ) ;
105140
106141 if ( string . IsNullOrEmpty ( querySearchString ) )
107142 return new List < Result > ( ) ;
108143
109144 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 ) ;
115150 }
116151
117152 public bool IsFileContentSearch ( string actionKeyword )
@@ -138,28 +173,30 @@ public async Task<List<Result>> TopLevelDirectorySearchBehaviourAsync(
138173 return await windowsIndexSearch ( query , querySearchString , token ) ;
139174 }
140175
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 )
142178 {
143179 var queryConstructor = new QueryConstructor ( settings ) ;
144180
145181 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 ) ;
151187 }
152188
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 )
154191 {
155192 var queryConstructor = new QueryConstructor ( settings ) ;
156193
157194 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 ) ;
163200 }
164201
165202 private bool UseWindowsIndexForDirectorySearch ( string locationPath )
@@ -170,11 +207,11 @@ private bool UseWindowsIndexForDirectorySearch(string locationPath)
170207 return false ;
171208
172209 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 ) ) )
175212 return false ;
176213
177214 return IndexSearch . PathIsIndexed ( pathToDirectory ) ;
178215 }
179216 }
180- }
217+ }
0 commit comments