From 82cfddbdb32c54b601aca8ef7ae6ade19afa571c Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Mon, 8 Jun 2020 19:21:47 +1000 Subject: [PATCH] add ordering to file and folder results --- .../DirectoryInfo/DirectoryInfoSearch.cs | 2 +- .../Search/WindowsIndex/IndexSearch.cs | 33 ++++++++++--------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/DirectoryInfo/DirectoryInfoSearch.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/DirectoryInfo/DirectoryInfoSearch.cs index bf2629dc5..b198395b8 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/DirectoryInfo/DirectoryInfoSearch.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/DirectoryInfo/DirectoryInfoSearch.cs @@ -90,7 +90,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo } // Intial ordering, this order can be updated later by UpdateResultView.MainViewModel based on history of user selection. - return results.Concat(folderList.OrderBy(x => x.Title)).Concat(fileList.OrderBy(x => x.Title)).ToList(); //<============= MOVE OUT + return results.Concat(folderList.OrderBy(x => x.Title)).Concat(fileList.OrderBy(x => x.Title)).ToList(); } } } diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearch.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearch.cs index c0e7474d9..5401c2845 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearch.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearch.cs @@ -3,6 +3,7 @@ using Microsoft.Search.Interop; using System; using System.Collections.Generic; using System.Data.OleDb; +using System.Linq; using System.Text.RegularExpressions; namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex @@ -29,6 +30,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex internal List ExecuteWindowsIndexSearch(string indexQueryString, string connectionString, Query query) { + var folderResults = new List(); + var fileResults = new List(); var results = new List(); try @@ -48,11 +51,18 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex { if (dataReaderResults.GetValue(0) != DBNull.Value && dataReaderResults.GetValue(1) != DBNull.Value) { - results.Add(CreateResult( - dataReaderResults.GetString(0), - dataReaderResults.GetString(1), - dataReaderResults.GetString(2), - query)); + if (dataReaderResults.GetString(2) == "Directory") + { + folderResults.Add(resultManager.CreateFolderResult( + dataReaderResults.GetString(0), + Constants.DefaultFolderSubtitleString, + dataReaderResults.GetString(1), + query, true, true)); + } + else + { + fileResults.Add(resultManager.CreateFileResult(dataReaderResults.GetString(1), query, true, true)); + } } } } @@ -70,17 +80,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex LogException("General error from performing index search", e); } - return results; - } - - private Result CreateResult(string filename, string path, string fileType, Query query) - { - if (fileType == "Directory") - return resultManager.CreateFolderResult(filename, Constants.DefaultFolderSubtitleString, path, query, true, true); - else - { - return resultManager.CreateFileResult(path, query, true, true); - } + // Intial ordering, this order can be updated later by UpdateResultView.MainViewModel based on history of user selection. + return results.Concat(folderResults.OrderBy(x => x.Title)).Concat(fileResults.OrderBy(x => x.Title)).ToList(); ; } internal List WindowsIndexSearch(string searchString, string connectionString, Func constructQuery, Query query)