From 472f4a5f49308a873749f794f6e121ba29a1c4a8 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Sun, 24 May 2020 19:15:13 +1000 Subject: [PATCH] Move ReservedStringPattern to IndexSearcher class --- Plugins/Flow.Launcher.Plugin.Explorer/Main.cs | 10 ++-------- .../Search/WindowsIndex/IndexSearcher.cs | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs index 80f872cf6..e5c9e8e2f 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs @@ -1,4 +1,4 @@ -using Flow.Launcher.Infrastructure.Storage; +using Flow.Launcher.Infrastructure.Storage; using Flow.Launcher.Plugin.Explorer.Search; using Flow.Launcher.Plugin.Explorer.ViewModels; using Flow.Launcher.Plugin.Explorer.Views; @@ -16,9 +16,6 @@ namespace Flow.Launcher.Plugin.Explorer private SettingsViewModel _viewModel; - // Reserved keywords in oleDB - private string ReservedStringPattern = @"^[\/\\\$\%]+$"; - public Control CreateSettingPanel() { return new ExplorerSettings(); @@ -44,10 +41,7 @@ namespace Flow.Launcher.Plugin.Explorer if (string.IsNullOrEmpty(query.Search)) return results; - var regexMatch = Regex.Match(query.Search, ReservedStringPattern); - - if (regexMatch.Success) - return results; + return new SearchManager(_settings, Context).Search(query); return new SearchManager(_settings, Context).Search(query.Search); } diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearcher.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearcher.cs index 56ed8ddc6..9f99a6248 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearcher.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearcher.cs @@ -1,4 +1,4 @@ -using Flow.Launcher.Infrastructure.Logger; +using Flow.Launcher.Infrastructure.Logger; using Flow.Launcher.Plugin.SharedCommands; using Microsoft.Search.Interop; using System; @@ -6,11 +6,14 @@ using System.Collections.Generic; using System.ComponentModel; using System.Data.OleDb; using System.Diagnostics; +using System.Text.RegularExpressions; namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex { internal class IndexSearcher { + private readonly object _lock = new object(); + public OleDbConnection conn; public OleDbCommand command; @@ -18,8 +21,9 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex public OleDbDataReader dataReaderResults; private PluginInitContext _context; - - private readonly object _lock = new object(); + + // Reserved keywords in oleDB + private string ReservedStringPattern = @"^[\/\\\$\%]+$"; public IndexSearcher(PluginInitContext context) { @@ -95,6 +99,11 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex internal List WindowsIndexSearch(string searchString, string connectionString, Func constructQuery) { + var regexMatch = Regex.Match(searchString, ReservedStringPattern); + + if (regexMatch.Success) + return new List(); + lock (_lock) { var constructedQuery = constructQuery(searchString);