mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 11:46:30 +02:00
[PTRun][Search]Add setting to exclude files/patterns from indexer (#31459)
* Add patterns exclusion to PTRun indexer * Apply xaml styling * Fix pattern escaping issues * Add placeholder to indexer exclusion options * Add placeholder text to textboxes * Fix failing to split multiline text in indexer settings * Add placeholder text to checkbox and textbox setting * Change generated source comments to english
This commit is contained in:
@@ -65,7 +65,7 @@ namespace Microsoft.Plugin.Indexer.SearchHelper
|
||||
return results;
|
||||
}
|
||||
|
||||
public static void ModifyQueryHelper(ref ISearchQueryHelper queryHelper, string pattern)
|
||||
public static void ModifyQueryHelper(ref ISearchQueryHelper queryHelper, string pattern, List<string> excludedPatterns = null)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(pattern);
|
||||
|
||||
@@ -88,6 +88,35 @@ namespace Microsoft.Plugin.Indexer.SearchHelper
|
||||
queryHelper.QueryWhereRestrictions += " AND Contains(System.FileName, '" + pattern + "') ";
|
||||
}
|
||||
}
|
||||
|
||||
if (excludedPatterns != null)
|
||||
{
|
||||
foreach (string p in excludedPatterns)
|
||||
{
|
||||
if (p == string.Empty)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var excludedPattern = p;
|
||||
|
||||
excludedPattern = excludedPattern.Replace("\\", "/", StringComparison.Ordinal);
|
||||
|
||||
if (excludedPattern.Contains('*', StringComparison.Ordinal) || excludedPattern.Contains('?', StringComparison.Ordinal))
|
||||
{
|
||||
excludedPattern = excludedPattern
|
||||
.Replace("%", "[%]", StringComparison.Ordinal)
|
||||
.Replace("_", "[_]", StringComparison.Ordinal)
|
||||
.Replace("*", "%", StringComparison.Ordinal)
|
||||
.Replace("?", "_", StringComparison.Ordinal);
|
||||
queryHelper.QueryWhereRestrictions += " AND System.ItemUrl NOT LIKE '%" + excludedPattern + "%' ";
|
||||
}
|
||||
else
|
||||
{
|
||||
queryHelper.QueryWhereRestrictions += " AND NOT Contains(System.ItemUrl, '" + excludedPattern + "') ";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void InitQueryHelper(out ISearchQueryHelper queryHelper, ISearchManager manager, int maxCount, bool displayHiddenFiles)
|
||||
@@ -122,13 +151,14 @@ namespace Microsoft.Plugin.Indexer.SearchHelper
|
||||
queryHelper.QuerySorting = "System.DateModified DESC";
|
||||
}
|
||||
|
||||
public IEnumerable<SearchResult> Search(string keyword, ISearchManager manager, string pattern = "*", int maxCount = 30)
|
||||
public IEnumerable<SearchResult> Search(string keyword, ISearchManager manager, string pattern = "*", List<string> excludedPatterns = null, int maxCount = 30)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(manager);
|
||||
excludedPatterns ??= new List<string>();
|
||||
|
||||
ISearchQueryHelper queryHelper;
|
||||
InitQueryHelper(out queryHelper, manager, maxCount, DisplayHiddenFiles);
|
||||
ModifyQueryHelper(ref queryHelper, pattern);
|
||||
ModifyQueryHelper(ref queryHelper, pattern, excludedPatterns);
|
||||
return ExecuteQuery(queryHelper, keyword);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user