Skip to content

Commit 8abd97d

Browse files
committed
add file content search to Index Search
1 parent 08bfa8d commit 8abd97d

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@ internal static class Constants
2525
internal const char DirectorySeperator = '\\';
2626

2727
internal const string WindowsIndexingOptions = "srchadmin.dll";
28+
29+
internal const string WindowsIndexFileContentSearchHotkey = "content:";
2830
}
2931
}

Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ internal List<Result> Search(Query query)
4242
if (string.IsNullOrEmpty(querySearch))
4343
return results;
4444

45+
if (IsFileContentSearch(querySearch))
46+
return WindowsIndexFileContentSearch(query, querySearch);
47+
4548
var isEnvironmentVariable = EnvironmentVariables.IsEnvironmentVariableSearch(querySearch);
4649

4750
if (isEnvironmentVariable)
@@ -74,6 +77,30 @@ internal List<Result> Search(Query query)
7477
return results;
7578
}
7679

80+
private List<Result> WindowsIndexFileContentSearch(Query query, string querySearchString)
81+
{
82+
var queryConstructor = new QueryConstructor(settings);
83+
84+
var updatedQuerySearchString = querySearchString
85+
.Substring(querySearchString
86+
.IndexOf(Constants.WindowsIndexFileContentSearchHotkey)
87+
+ Constants.WindowsIndexFileContentSearchHotkey.Length);
88+
89+
if (string.IsNullOrEmpty(updatedQuerySearchString))
90+
return new List<Result>();
91+
92+
return indexSearch.WindowsIndexSearch(updatedQuerySearchString.TrimStart(),
93+
queryConstructor.CreateQueryHelper().ConnectionString,
94+
queryConstructor.QueryForFileContentSearch,
95+
query);
96+
}
97+
98+
public bool IsFileContentSearch(string querySearch)
99+
{
100+
return querySearch.StartsWith(Constants.WindowsIndexFileContentSearchHotkey,
101+
StringComparison.OrdinalIgnoreCase);
102+
}
103+
77104
private List<Result> DirectoryInfoClassSearch(Query query, string querySearch)
78105
{
79106
var directoryInfoSearch = new DirectoryInfoSearch(context);

Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/QueryConstructor.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,23 @@ public string QueryWhereRestrictionsForAllFilesAndFoldersSearch()
117117
{
118118
return $"scope='file:'";
119119
}
120+
121+
///<summary>
122+
/// Search will be performed on all indexed file contents for the specified search keywords.
123+
///</summary>
124+
public string QueryForFileContentSearch(string userSearchString)
125+
{
126+
string query = "SELECT TOP " + settings.MaxResult + $" {CreateBaseQuery().QuerySelectColumns} FROM {SystemIndex} WHERE ";
127+
128+
return query + QueryWhereRestrictionsForFileContentSearch(userSearchString) + " AND " + QueryWhereRestrictionsForAllFilesAndFoldersSearch();
129+
}
130+
131+
///<summary>
132+
/// Set the required WHERE clause restriction to search within file content.
133+
///</summary>
134+
public string QueryWhereRestrictionsForFileContentSearch(string searchQuery)
135+
{
136+
return $"FREETEXT('{searchQuery}')";
137+
}
120138
}
121139
}

0 commit comments

Comments
 (0)