mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
[PT Run] Split indexer plugin's queries into a fast and slow query (#5748)
* Added regex code * Added regex based method to remove all LIKE queries * Made regex readonly * Added plugin interface and code to execute slower plugins after the fast plugins * Added scoring for indexer and added statement to remove old indexer results * Refactored from master and added thread sleep for debugging * Removed lock from indexer plugin and added checks to avoid exceptions * Remove debug statement * Removed selected index update and fixed tests not building * Added tests * Removed scoring * Removed lock * Resolve merge conflicts * Moved dispatcher code to function and add parallel foreach loop * Removed DelayedExec metadata and modified QueryForPlugin to run only delayed exec plugins when bool param is true * Removed metadata from plugin.json
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.Search.Interop;
|
||||
|
||||
namespace Microsoft.Plugin.Indexer.SearchHelper
|
||||
@@ -13,8 +15,9 @@ namespace Microsoft.Plugin.Indexer.SearchHelper
|
||||
public bool DisplayHiddenFiles { get; set; }
|
||||
|
||||
private readonly ISearch windowsIndexerSearch;
|
||||
private readonly object _lock = new object();
|
||||
|
||||
private const uint _fileAttributeHidden = 0x2;
|
||||
private static readonly Regex _likeRegex = new Regex(@"[^\s(]+\s+LIKE\s+'([^']|'')*'\s+OR\s+", RegexOptions.Compiled);
|
||||
|
||||
public WindowsSearchAPI(ISearch windowsIndexerSearch, bool displayHiddenFiles = false)
|
||||
{
|
||||
@@ -22,7 +25,7 @@ namespace Microsoft.Plugin.Indexer.SearchHelper
|
||||
DisplayHiddenFiles = displayHiddenFiles;
|
||||
}
|
||||
|
||||
public List<SearchResult> ExecuteQuery(ISearchQueryHelper queryHelper, string keyword)
|
||||
public List<SearchResult> ExecuteQuery(ISearchQueryHelper queryHelper, string keyword, bool isFullQuery = false)
|
||||
{
|
||||
if (queryHelper == null)
|
||||
{
|
||||
@@ -33,6 +36,17 @@ namespace Microsoft.Plugin.Indexer.SearchHelper
|
||||
|
||||
// Generate SQL from our parameters, converting the userQuery from AQS->WHERE clause
|
||||
string sqlQuery = queryHelper.GenerateSQLFromUserQuery(keyword);
|
||||
var simplifiedQuery = SimplifyQuery(sqlQuery);
|
||||
|
||||
if (!isFullQuery)
|
||||
{
|
||||
sqlQuery = simplifiedQuery;
|
||||
}
|
||||
else if (simplifiedQuery.Equals(sqlQuery, StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
// if a full query is requested but there is no difference between the queries, return empty results
|
||||
return results;
|
||||
}
|
||||
|
||||
// execute the command, which returns the results as an OleDBResults.
|
||||
List<OleDBResult> oleDBResults = windowsIndexerSearch.Query(queryHelper.ConnectionString, sqlQuery);
|
||||
@@ -121,15 +135,17 @@ namespace Microsoft.Plugin.Indexer.SearchHelper
|
||||
queryHelper.QuerySorting = "System.DateModified DESC";
|
||||
}
|
||||
|
||||
public IEnumerable<SearchResult> Search(string keyword, string pattern = "*", int maxCount = 30)
|
||||
public IEnumerable<SearchResult> Search(string keyword, bool isFullQuery = false, string pattern = "*", int maxCount = 30)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
ISearchQueryHelper queryHelper;
|
||||
InitQueryHelper(out queryHelper, maxCount);
|
||||
ModifyQueryHelper(ref queryHelper, pattern);
|
||||
return ExecuteQuery(queryHelper, keyword);
|
||||
}
|
||||
ISearchQueryHelper queryHelper;
|
||||
InitQueryHelper(out queryHelper, maxCount);
|
||||
ModifyQueryHelper(ref queryHelper, pattern);
|
||||
return ExecuteQuery(queryHelper, keyword, isFullQuery);
|
||||
}
|
||||
|
||||
public static string SimplifyQuery(string sqlQuery)
|
||||
{
|
||||
return _likeRegex.Replace(sqlQuery, string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user