Skip to content

Commit bc0146e

Browse files
committed
Use Window Search Orderby instead of getting the result and order them by filename
1 parent 79962fb commit bc0146e

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ internal IndexSearch(PluginInitContext context)
2424

2525
internal async Task<List<Result>> ExecuteWindowsIndexSearchAsync(string indexQueryString, string connectionString, Query query, CancellationToken token)
2626
{
27-
var folderResults = new List<Result>();
28-
var fileResults = new List<Result>();
2927
var results = new List<Result>();
28+
var fileResults = new List<Result>();
3029

3130
try
3231
{
@@ -55,7 +54,7 @@ internal async Task<List<Result>> ExecuteWindowsIndexSearchAsync(string indexQue
5554

5655
if (dataReaderResults.GetString(2) == "Directory")
5756
{
58-
folderResults.Add(resultManager.CreateFolderResult(
57+
results.Add(resultManager.CreateFolderResult(
5958
dataReaderResults.GetString(0),
6059
path,
6160
path,
@@ -83,8 +82,10 @@ internal async Task<List<Result>> ExecuteWindowsIndexSearchAsync(string indexQue
8382
LogException("General error from performing index search", e);
8483
}
8584

85+
results.AddRange(fileResults);
86+
8687
// Intial ordering, this order can be updated later by UpdateResultView.MainViewModel based on history of user selection.
87-
return results.Concat(folderResults.OrderBy(x => x.Title)).Concat(fileResults.OrderBy(x => x.Title)).ToList(); ;
88+
return results;
8889
}
8990

9091
internal async Task<List<Result>> WindowsIndexSearchAsync(string searchString, string connectionString,

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ internal CSearchQueryHelper CreateQueryHelper()
4242

4343
// Get the ISearchQueryHelper which will help us to translate AQS --> SQL necessary to query the indexer
4444
var queryHelper = catalogManager.GetQueryHelper();
45-
45+
4646
return queryHelper;
4747
}
4848

@@ -81,11 +81,9 @@ private string QueryWhereRestrictionsFromLocationPath(string path, string search
8181
var previousLevelDirectory = path.Substring(0, indexOfSeparator);
8282

8383
if (string.IsNullOrEmpty(itemName))
84-
return searchDepth + $"{previousLevelDirectory}'";
84+
return $"{searchDepth}{previousLevelDirectory}'{QueryOrderByFileNameRestriction}";
8585

86-
return $"(System.FileName LIKE '{itemName}%' " +
87-
$"OR CONTAINS(System.FileName,'\"{itemName}*\"',1033)) AND " +
88-
searchDepth + $"{previousLevelDirectory}'";
86+
return $"(System.FileName LIKE '{itemName}%' OR CONTAINS(System.FileName,'\"{itemName}*\"',1033)) AND {searchDepth}{previousLevelDirectory}' {QueryOrderByFileNameRestriction}";
8987
}
9088

9189
///<summary>
@@ -98,7 +96,7 @@ public string QueryForTopLevelDirectorySearch(string path)
9896
if (path.LastIndexOf(Constants.AllFilesFolderSearchWildcard) > path.LastIndexOf(Constants.DirectorySeperator))
9997
return query + QueryWhereRestrictionsForTopLevelDirectoryAllFilesAndFoldersSearch(path);
10098

101-
return query + QueryWhereRestrictionsForTopLevelDirectorySearch(path);
99+
return query + QueryWhereRestrictionsForTopLevelDirectorySearch(path) + QueryOrderByFileNameRestriction;
102100
}
103101

104102
///<summary>
@@ -107,16 +105,17 @@ public string QueryForTopLevelDirectorySearch(string path)
107105
public string QueryForAllFilesAndFolders(string userSearchString)
108106
{
109107
// Generate SQL from constructed parameters, converting the userSearchString from AQS->WHERE clause
110-
return CreateBaseQuery().GenerateSQLFromUserQuery(userSearchString) + " AND " + QueryWhereRestrictionsForAllFilesAndFoldersSearch();
108+
return CreateBaseQuery().GenerateSQLFromUserQuery(userSearchString) + " AND " + QueryWhereRestrictionsForAllFilesAndFoldersSearch
109+
+ QueryOrderByFileNameRestriction;
111110
}
112111

113112
///<summary>
114113
/// Set the required WHERE clause restriction to search for all files and folders.
115114
///</summary>
116-
public string QueryWhereRestrictionsForAllFilesAndFoldersSearch()
117-
{
118-
return $"scope='file:'";
119-
}
115+
public const string QueryWhereRestrictionsForAllFilesAndFoldersSearch = "scope='file:'";
116+
117+
public const string QueryOrderByFileNameRestriction = " ORDER BY System.FileName";
118+
120119

121120
///<summary>
122121
/// Search will be performed on all indexed file contents for the specified search keywords.
@@ -125,7 +124,8 @@ public string QueryForFileContentSearch(string userSearchString)
125124
{
126125
string query = "SELECT TOP " + settings.MaxResult + $" {CreateBaseQuery().QuerySelectColumns} FROM {SystemIndex} WHERE ";
127126

128-
return query + QueryWhereRestrictionsForFileContentSearch(userSearchString) + " AND " + QueryWhereRestrictionsForAllFilesAndFoldersSearch();
127+
return query + QueryWhereRestrictionsForFileContentSearch(userSearchString) + " AND " + QueryWhereRestrictionsForAllFilesAndFoldersSearch
128+
+ QueryOrderByFileNameRestriction;
129129
}
130130

131131
///<summary>

0 commit comments

Comments
 (0)