Skip to content

Commit

Permalink
Add proper wildcard support
Browse files Browse the repository at this point in the history
  • Loading branch information
david-poindexter committed Aug 5, 2020
1 parent 577a711 commit a09212c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
4 changes: 2 additions & 2 deletions DNN Platform/Library/Services/FileSystem/FolderManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1845,11 +1845,11 @@ private static Regex WildcardToRegex(string pattern)
{
if (!pattern.Contains("*") && !pattern.Contains("?"))
{
pattern = "^" + pattern + ".*$";
pattern = ".*" + Regex.Escape(pattern) + ".*";
}
else
{
pattern = "^" + Regex.Escape(pattern).Replace(@"\*", ".*").Replace(@"\?", ".") + "$";
pattern = Regex.Escape(pattern).Replace(@"\*", ".*").Replace(@"\?", ".");
}

return RegexUtils.GetCachedRegex(pattern, RegexOptions.IgnoreCase);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,14 @@ public IList<IFileInfo> SearchFolderContent(int moduleId, IFolderInfo folder, bo

search = (search ?? string.Empty).Trim();

// Lucene does not support wildcards as the beginning of the search
// For file names we can remove any existing wildcard at the beginning
var cleanedKeywords = TrimStartWildCards(search);

var files = FolderManager.Instance.SearchFiles(folder, cleanedKeywords, recursive);
var files = FolderManager.Instance.SearchFiles(folder, search, recursive);
var sortProperties = SortProperties.Parse(sorting);
var sortedFiles = SortFiles(files, sortProperties).ToList();
totalCount = sortedFiles.Count;

return sortedFiles.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}

private static string TrimStartWildCards(string search)
{
var keywords = from keyword in search.Split(' ')
select keyword.TrimStart('*', '?');
search = string.Join(" ", keywords);
return search;
}

private static IEnumerable<IFileInfo> SortFiles(IEnumerable<IFileInfo> files, SortProperties sortProperties)
{
switch (sortProperties.Column)
Expand Down

0 comments on commit a09212c

Please sign in to comment.