Skip to content

Commit

Permalink
Merge pull request #3962 from david-poindexter/wildcard-search
Browse files Browse the repository at this point in the history
Add better wildcard file search support
  • Loading branch information
mitchelsellers authored Aug 6, 2020
2 parents 20193d7 + a09212c commit c717cac
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 16 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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
margin: 0px;
list-style: none;
box-sizing: border-box;
height: 28px;
}
}

Expand Down

0 comments on commit c717cac

Please sign in to comment.