示例#1
0
        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();
        }
示例#2
0
        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();
        }
示例#3
0
        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();
            });
        }
示例#4
0
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     Indexer.Dispose();
 }