add file content search to Index Search

This commit is contained in:
Jeremy Wu 2020-07-12 22:43:38 +10:00
parent 08bfa8da9c
commit 8abd97d523
3 changed files with 47 additions and 0 deletions

View file

@ -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:";
}
}

View file

@ -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<Result> 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<Result>();
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<Result> DirectoryInfoClassSearch(Query query, string querySearch)
{
var directoryInfoSearch = new DirectoryInfoSearch(context);

View file

@ -117,5 +117,23 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex
{
return $"scope='file:'";
}
///<summary>
/// Search will be performed on all indexed file contents for the specified search keywords.
///</summary>
public string QueryForFileContentSearch(string userSearchString)
{
string query = "SELECT TOP " + settings.MaxResult + $" {CreateBaseQuery().QuerySelectColumns} FROM {SystemIndex} WHERE ";
return query + QueryWhereRestrictionsForFileContentSearch(userSearchString) + " AND " + QueryWhereRestrictionsForAllFilesAndFoldersSearch();
}
///<summary>
/// Set the required WHERE clause restriction to search within file content.
///</summary>
public string QueryWhereRestrictionsForFileContentSearch(string searchQuery)
{
return $"FREETEXT('{searchQuery}')";
}
}
}