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 ShouldRemoveFileWhenRenamed() { var file1 = Path.Combine(_directory, "1.txt"); File.WriteAllText(file1, "hello 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.AddFile(file1); WaitForIndexed(indexer, events); var result = indexer.Search("hello world"); CollectionAssert.AreEquivalent(new[] { file1 }, result); File.Move(file1, Path.Combine(_directory, "2.txt")); WaitForIndexed(indexer, events); result = indexer.Search("hello"); CollectionAssert.IsEmpty(result); indexer.Dispose(); }
private void button1_Click(object sender, EventArgs e) { lbKeywords.DataSource = null; lvHits.Items.Clear(); background((sentBy, args) => { if (_indexer != null) { _indexer.Dispose(); } showProgress("Reading index configuration ...", EventLogEntryType.Information); _indexer = Indexer <BPlusString, BPlusListLong> .LoadConfigFromFile(null); _indexer.OnProgress += new Indexer <BPlusString, BPlusListLong> .ProgressEventHandler(indexer_OnProgress); showProgress("Creating all indexes ...", EventLogEntryType.Information); // _indexer.CreateAllIndexes(); // _indexer.Indexes["accession_source"].Create(); }); }
protected override void Dispose(bool disposing) { base.Dispose(disposing); Indexer.Dispose(); }