diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs index d474fb0e7..e61165c3d 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs @@ -25,5 +25,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search internal const char DirectorySeperator = '\\'; internal const string WindowsIndexingOptions = "srchadmin.dll"; + + internal const string WindowsIndexFileContentSearchHotkey = "content:"; } } diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index f814962ba..631dd0c31 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -42,6 +42,9 @@ namespace Flow.Launcher.Plugin.Explorer.Search if (string.IsNullOrEmpty(querySearch)) return results; + if (IsFileContentSearch(querySearch)) + return WindowsIndexFileContentSearch(query, querySearch); + var isEnvironmentVariable = EnvironmentVariables.IsEnvironmentVariableSearch(querySearch); if (isEnvironmentVariable) @@ -74,6 +77,30 @@ namespace Flow.Launcher.Plugin.Explorer.Search return results; } + private List WindowsIndexFileContentSearch(Query query, string querySearchString) + { + var queryConstructor = new QueryConstructor(settings); + + var updatedQuerySearchString = querySearchString + .Substring(querySearchString + .IndexOf(Constants.WindowsIndexFileContentSearchHotkey) + + Constants.WindowsIndexFileContentSearchHotkey.Length); + + if (string.IsNullOrEmpty(updatedQuerySearchString)) + return new List(); + + return indexSearch.WindowsIndexSearch(updatedQuerySearchString.TrimStart(), + queryConstructor.CreateQueryHelper().ConnectionString, + queryConstructor.QueryForFileContentSearch, + query); + } + + public bool IsFileContentSearch(string querySearch) + { + return querySearch.StartsWith(Constants.WindowsIndexFileContentSearchHotkey, + StringComparison.OrdinalIgnoreCase); + } + private List DirectoryInfoClassSearch(Query query, string querySearch) { var directoryInfoSearch = new DirectoryInfoSearch(context); diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/QueryConstructor.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/QueryConstructor.cs index f4480eea7..393c1514d 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/QueryConstructor.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/QueryConstructor.cs @@ -117,5 +117,23 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex { return $"scope='file:'"; } + + /// + /// Search will be performed on all indexed file contents for the specified search keywords. + /// + public string QueryForFileContentSearch(string userSearchString) + { + string query = "SELECT TOP " + settings.MaxResult + $" {CreateBaseQuery().QuerySelectColumns} FROM {SystemIndex} WHERE "; + + return query + QueryWhereRestrictionsForFileContentSearch(userSearchString) + " AND " + QueryWhereRestrictionsForAllFilesAndFoldersSearch(); + } + + /// + /// Set the required WHERE clause restriction to search within file content. + /// + public string QueryWhereRestrictionsForFileContentSearch(string searchQuery) + { + return $"FREETEXT('{searchQuery}')"; + } } }