예제 #1
0
        public void Check_IndexReader_Get_Closed_When_Creating_New()
        {
            var dir     = new RAMDirectory();
            var writer  = new IndexWriter(dir, new SimpleAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
            var manager = new SearcherManager(dir);

            var searcher1 = manager.GetSearcher();

            // Change the index
            writer.AddDocument(new Document());
            writer.Commit();

            // Reopen the IndexReader
            manager.MaybeReopen();

            var searcher2 = manager.GetSearcher();

            Assert.AreNotEqual(searcher1.IndexReader, searcher2.IndexReader, "A new IndexReader was not created.");
            manager.ReleaseSearcher(searcher2);

            manager.ReleaseSearcher(searcher1);
            Assert.Throws <AlreadyClosedException>(() => manager.ReleaseSearcher(searcher1));
        }
        public void Find_Item_Add_Item_And_Find_Both_Items()
        {
            var anders = "Anders";
            var anja   = "Anja";

            _indexWriter.AddDocument(CreateDocument(anders));
            _indexWriter.Commit();

            var manager = new SearcherManager(_dir);

            var result = Search(manager, anders);

            CollectionAssert.AreEquivalent(result, new[] { anders }, "Did not find {0}", anders);

            _indexWriter.AddDocument(CreateDocument(anja));
            _indexWriter.Commit();

            manager.MaybeReopen();

            result = Search(manager, "An*");

            CollectionAssert.AreEquivalent(result, new[] { anders, anja });
        }