public void ShouldNotSearchDeleted() { var file1 = Path.Combine(_directory, "1.txt"); var file2 = Path.Combine(_directory, "2.txt"); var file3 = Path.Combine(_directory, "3.txt"); var file4 = Path.Combine(_directory, "4.pdf"); File.WriteAllText(file1, "hello world"); File.WriteAllText(file2, "hello pretty world"); File.WriteAllText(file3, "just hello"); File.WriteAllText(file4, "hello ugly world"); var analyzer = new SimpleAnalyzer(); var store = new InMemoryStore(); BlockingCollection <IndexingEventArgs> events = new BlockingCollection <IndexingEventArgs>(); var indexer = new Indexer(new SearchIndex(analyzer, store)); indexer.IndexingProgress += (o, e) => events.Add(e); indexer.AddDirectory(_directory, "*.txt"); WaitForIndexed(indexer, events); File.Delete(file1); WaitForIndexed(indexer, events); var result = indexer.Search("hello world"); CollectionAssert.AreEquivalent(new[] { file2 }, result); indexer.Dispose(); }
public void MainTest() { SimpleByWordParser parser = new SimpleByWordParser(); Indexer indexer = new Indexer(parser); var testFilesDirectory = @"D:\MyProjects\Tests"; var testFileName = @"text.txt"; CreateTestFile(testFilesDirectory, testFileName); indexer.AddFile(testFilesDirectory + "\\" + testFileName); for (int i = 0; i < 2; i++) { var newDirectory = testFilesDirectory + "\\" + i + "Test"; Directory.CreateDirectory(newDirectory); for (int j = 0; j < 5; j++) { CreateTestFile(newDirectory, j + testFileName); } indexer.AddDirectory(newDirectory); } var findedFiles = indexer.Find("AAA"); Assert.IsTrue(findedFiles.Count == 11); }
private void AddDirectory() { string directory; if (!_dialogService.ShowOpenFolderDialog(Resources.OpenDirectoryDescription, out directory)) { return; } if (_trackingPaths.Contains(directory)) { return; } _indexer.AddDirectory(directory, TxtFilter); _trackingPaths.Add(directory); }
public void WatcherTest() { SimpleByWordParser parser = new SimpleByWordParser(); Indexer indexer = new Indexer(parser); var testFilesDirectory = @"D:\MyProjects\Tests"; var testFileName = @"text.txt"; CreateTestFile(testFilesDirectory, testFileName); indexer.AddFile(testFilesDirectory + "\\" + testFileName); var findedFiles = indexer.Find("AAA"); Assert.AreEqual(1, findedFiles.Count); File.Delete(testFilesDirectory + "\\" + testFileName); Thread.Sleep(1000); findedFiles = indexer.Find("AAA"); Assert.AreEqual(0, findedFiles.Count); indexer.AddDirectory(testFilesDirectory); using (var a = File.CreateText(testFilesDirectory + "\\1" + testFileName)) { a.Write("WWW"); } Thread.Sleep(1000); findedFiles = indexer.Find("WWW"); Assert.AreEqual(1, findedFiles.Count); var nextFolder = testFilesDirectory + "\\" + "tst"; Directory.CreateDirectory(nextFolder); using (var a = File.CreateText(nextFolder + "\\" + testFileName)) { a.Write("GGG"); } indexer.AddFile(nextFolder + "\\" + testFileName); using (var a = File.CreateText(nextFolder + "\\" + testFileName)) { a.Write("ZZZ"); } Thread.Sleep(2000); findedFiles = indexer.Find("ZZZ"); Assert.AreEqual(1, findedFiles.Count); }
static void Main(string[] args) { WriteHelp(); Boolean exit = false; //Созаем парсер var textParser = new SimpleByWordParser(); //Создаем индексатор на основе простого парсера var indexer = new Indexer(textParser); while (!exit) { var res = Console.ReadLine() ?? ""; exit = res.ToLowerInvariant().Equals("q"); try { if (!exit) { if (res.StartsWith("addc")) { var directoryPath = res.Remove(0, 4).Trim(); indexer.AddDirectory(directoryPath); } else if (res.StartsWith("add")) { var filePath = res.Remove(0, 3).Trim(); indexer.AddFile(filePath); } else if (res.StartsWith("?")) { var quest = res.Remove(0, 1).Trim(); var result = indexer.Find(quest); if (result.Count == 0) { Console.WriteLine("В коллекции нет файлов!"); } else { foreach (var finddFiles in result) { Console.WriteLine(finddFiles); } } } else if (res.StartsWith("files")) { var files = indexer.GetAddedFiles(); foreach (var file in files) { Console.WriteLine(file); } } else if (res.StartsWith("cats")) { var cats = indexer.GetAddedCatalogs(); foreach (var cat in cats) { Console.WriteLine(cat); } } else if (res.StartsWith("help")) { WriteHelp(); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } } }