diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index 6d74775cc..6e8a61095 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -1,4 +1,4 @@ -using Flow.Launcher.Plugin.Explorer.Search.WindowsIndex; +using Flow.Launcher.Plugin.Explorer.Search.WindowsIndex; using System; using System.Collections.Generic; @@ -9,10 +9,31 @@ namespace Flow.Launcher.Plugin.Explorer.Search private Settings _settings; private PluginInitContext _context; + private IndexSearcher searcher; + public SearchManager(Settings settings, PluginInitContext context) { _settings = settings; _context = context; + searcher = new IndexSearcher(_context); + } + + public List Search(string querySearchString) + { + if (IsLocationPathString(querySearchString)) + { + return TopLevelFolderSearchBehaviour(WindowsIndexTopLevelFolderSearch, + DirectoryInfoClassSearch, + WindowsIndexExists, + querySearchString); + } + + return WindowsIndexFilesAndFoldersSearch(querySearchString); + } + + private List DirectoryInfoClassSearch(string arg) + { + throw new NotImplementedException(); } /// @@ -62,15 +83,27 @@ namespace Flow.Launcher.Plugin.Explorer.Search return results; } - internal List WindowsIndexFilesAndFoldersSearch(string querySearchString) + private List WindowsIndexFilesAndFoldersSearch(string querySearchString) { var queryConstructor = new QueryConstructor(_settings); - var searcher = new IndexSearcher(_context); - return searcher.WindowsIndexSearch(querySearchString, queryConstructor.CreateQueryHelper().ConnectionString, queryConstructor.QueryForAllFilesAndFolders); } + + private List WindowsIndexTopLevelFolderSearch(string path) + { + var queryConstructor = new QueryConstructor(_settings); + + return searcher.WindowsIndexSearch(path, + queryConstructor.CreateQueryHelper().ConnectionString, + queryConstructor.QueryForTopLevelDirectorySearch); + } + + private bool WindowsIndexExists(string path) + { + return searcher.PathIsIndexed(path); + } } } diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearcher.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearcher.cs index 837c316b0..56ed8ddc6 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearcher.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearcher.cs @@ -1,5 +1,6 @@ -using Flow.Launcher.Infrastructure.Logger; +using Flow.Launcher.Infrastructure.Logger; using Flow.Launcher.Plugin.SharedCommands; +using Microsoft.Search.Interop; using System; using System.Collections.Generic; using System.ComponentModel; @@ -100,5 +101,13 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex return ExecuteWindowsIndexSearch(constructedQuery, connectionString); } } + + internal bool PathIsIndexed(string path) + { + var csm = new CSearchManager(); + var indexManager = csm.GetCatalog("SystemIndex").GetCrawlScopeManager(); + + return indexManager.IncludedInCrawlScope(path) == 0; + } } }