Skip to content

Commit e179bcf

Browse files
authored
Improved reliability of the search experience (#6671)
1 parent 871b923 commit e179bcf

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

Files/Filesystem/Search/FolderSearch.cs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,23 @@ public class FolderSearch
4141

4242
public EventHandler SearchTick;
4343

44+
private bool IsAQSQuery => Query is not null && (Query.StartsWith("$") || Query.Contains(":"));
45+
46+
private string QueryWithWildcard
47+
{
48+
get
49+
{
50+
if (!string.IsNullOrEmpty(Query) && Query.Contains('.')) // ".docx" -> "*.docx"
51+
{
52+
var split = Query.Split('.');
53+
var leading = string.Join('.', split.SkipLast(1));
54+
var query = $"{leading}*.{split.Last()}";
55+
return $"{query}*";
56+
}
57+
return $"{Query}*";
58+
}
59+
}
60+
4461
public string AQSQuery
4562
{
4663
get
@@ -56,7 +73,7 @@ public string AQSQuery
5673
}
5774
else
5875
{
59-
return $"System.FileName:\"{Query}\"";
76+
return $"System.FileName:\"{QueryWithWildcard}\"";
6077
}
6178
}
6279
}
@@ -245,20 +262,12 @@ private async Task AddItemsAsync(string folder, IList<ListedItem> results, Cance
245262
if (workingFolder)
246263
{
247264
await SearchAsync(workingFolder, results, token);
248-
//foreach (var item in await SearchAsync(workingFolder))
249-
//{
250-
// results.Add(item);
251-
//}
252-
hiddenOnlyFromWin32 = true;
265+
hiddenOnlyFromWin32 = (results.Count != 0);
253266
}
254267

255-
if (!hiddenOnlyFromWin32 || UserSettingsService.FilesAndFoldersSettingsService.AreHiddenItemsVisible)
268+
if (!IsAQSQuery && (!hiddenOnlyFromWin32 || UserSettingsService.FilesAndFoldersSettingsService.AreHiddenItemsVisible))
256269
{
257270
await SearchWithWin32Async(folder, hiddenOnlyFromWin32, UsedMaxItemCount - (uint)results.Count, results, token);
258-
//foreach (var item in)
259-
//{
260-
// results.Add(item);
261-
//}
262271
}
263272
}
264273
}
@@ -269,7 +278,7 @@ private async Task SearchWithWin32Async(string folder, bool hiddenOnly, uint max
269278
(IntPtr hFile, WIN32_FIND_DATA findData) = await Task.Run(() =>
270279
{
271280
int additionalFlags = FIND_FIRST_EX_LARGE_FETCH;
272-
IntPtr hFileTsk = FindFirstFileExFromApp($"{folder}\\*{Query}*.*", FINDEX_INFO_LEVELS.FindExInfoBasic,
281+
IntPtr hFileTsk = FindFirstFileExFromApp($"{folder}\\{QueryWithWildcard}", FINDEX_INFO_LEVELS.FindExInfoBasic,
273282
out WIN32_FIND_DATA findDataTsk, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, additionalFlags);
274283
return (hFileTsk, findDataTsk);
275284
}).WithTimeoutAsync(TimeSpan.FromSeconds(5));

Files/Services/Implementation/FileTagsSettingsService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public FileTag GetTagById(string uid)
4444

4545
public IEnumerable<FileTag> GetTagsByName(string tagName)
4646
{
47-
return FileTagList.Where(x => x.TagName.Equals(tagName, StringComparison.OrdinalIgnoreCase));
47+
return FileTagList.Where(x => x.TagName.StartsWith(tagName, StringComparison.OrdinalIgnoreCase));
4848
}
4949
}
5050
}

Files/Views/ModernShellPage.xaml.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -661,9 +661,12 @@ private async void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, Keybo
661661
break;
662662
}
663663

664-
case (false, false, false, true, VirtualKey.F3): //f3
665-
case (true, false, false, true, VirtualKey.F): // ctrl + f
666-
NavToolbarViewModel.SwitchSearchBoxVisibility();
664+
case (false, false, false, _, VirtualKey.F3): //f3
665+
case (true, false, false, _, VirtualKey.F): // ctrl + f
666+
if (tabInstance || CurrentPageType == typeof(WidgetsPage))
667+
{
668+
NavToolbarViewModel.SwitchSearchBoxVisibility();
669+
}
667670
break;
668671

669672
case (true, true, false, true, VirtualKey.N): // ctrl + shift + n, new item
@@ -1137,7 +1140,7 @@ public class PathBoxItem
11371140
public class NavigationParams
11381141
{
11391142
public string NavPath { get; set; }
1140-
public string SelectItem { get; set;}
1143+
public string SelectItem { get; set; }
11411144
}
11421145

11431146
public class NavigationArguments

0 commit comments

Comments
 (0)