I have been using the library for a long time in my own goals to quickly find files on a PC - https://github.com/VladPVS/FastSearchLibrary
public static string _keywords = "TestFile, .rar, .zip, .mp3, Bloody6, Artificial";
public void TestSe()
{
CancellationTokenSource tokenSource = new CancellationTokenSource();
List<string> keywords = _keywords.Split(',').ToList(); // #2 <--------
//List<string> keywords = new List<string>() {
// @"TestFile",
// @".rar",
// @".zip",
// @".mp3",
// @"Bloody6",
// @"Artificial" }; // #1 <----------
List<string> folders = new List<string>();
foreach (DriveInfo drive in DriveInfo.GetDrives())
{
if (drive.IsReady)
{
string driveRoot = drive.RootDirectory.FullName;
folders.Add(driveRoot);
}
}
searcher = new FileSearcherMultiple(folders, (f) =>
{
foreach (var keyword in keywords)
if (f.Name.Contains(keyword))
return true;
return false;
}, tokenSource);
List<FileInfo> files = new List<FileInfo>();
searcher.FilesFound += (sndr, arg) =>
{
lock (locker)
{
arg.Files.ForEach((f) =>
{
files.Add(f);
new Thread(() =>
{
//my work
}).Start();
});
}
};
searcher.SearchCompleted += (sndr, arg) =>
{
//ended
};
searcher.StartSearchAsync();
}
I decided to display a list of keywords in the global string (as needed). But the search for some reason began to blunt. If you use the list directly as in #1, then it finds all files by keywords of 3000+ pieces. If you use #2, it finds 4-5 files by the keywords "Bloody6", "Artifical". What could be the problem?
Most likely because if you used _keywords.Split(',') it will return extensions with spaces :
e.g. [space].rar, [space].zip, [space].mp3, etc.
You need to trim these values:
_keywords.Split(',').Select(s => s.TrimStart()).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With