当前位置: 首页>>代码示例>>C#>>正文


C# Lucene.Net.Index.IndexWriter.Dispose方法代码示例

本文整理汇总了C#中Lucene.Net.Index.IndexWriter.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Lucene.Net.Index.IndexWriter.Dispose方法的具体用法?C# Lucene.Net.Index.IndexWriter.Dispose怎么用?C# Lucene.Net.Index.IndexWriter.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lucene.Net.Index.IndexWriter的用法示例。


在下文中一共展示了Lucene.Net.Index.IndexWriter.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateDummySearcher

        internal bool Validate = true; // set to false when doing performance testing

        #endregion Fields

        #region Methods

        // TODO: this should be setUp()....
        public virtual void CreateDummySearcher()
        {
            // Create a dummy index with nothing in it.
            // this could possibly fail if Lucene starts checking for docid ranges...
            d = NewDirectory();
            IndexWriter iw = new IndexWriter(d, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())));
            iw.AddDocument(new Document());
            iw.Dispose();
            r = DirectoryReader.Open(d);
            s = NewSearcher(r);
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:18,代码来源:TestScorerPerf.cs

示例2: SetUp

 public override void SetUp()
 {
     base.SetUp();
     Directory = NewDirectory();
     IndexWriter writer = new IndexWriter(Directory, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetMergePolicy(NewLogMergePolicy()));
     //writer.setNoCFSRatio(0.0);
     //writer.infoStream = System.out;
     FieldType customType = new FieldType(TextField.TYPE_STORED);
     customType.Tokenized = false;
     customType.StoreTermVectors = true;
     for (int i = 0; i < NumDocs; i++)
     {
         Documents.Document doc = new Documents.Document();
         Field fld = NewField("field", English.IntToEnglish(i), customType);
         doc.Add(fld);
         writer.AddDocument(doc);
     }
     writer.Dispose();
 }
开发者ID:WakeflyCBass,项目名称:lucenenet,代码行数:19,代码来源:TestMultiThreadTermVectors.cs

示例3: SearchFiltered

        public virtual void SearchFiltered(IndexWriter writer, Directory directory, Filter filter, bool fullMerge)
        {
            for (int i = 0; i < 60; i++) //Simple docs
            {
                Document doc = new Document();
                doc.Add(NewStringField(FIELD, Convert.ToString(i), Field.Store.YES));
                writer.AddDocument(doc);
            }
            if (fullMerge)
            {
                writer.ForceMerge(1);
            }
            writer.Dispose();

            BooleanQuery booleanQuery = new BooleanQuery();
            booleanQuery.Add(new TermQuery(new Term(FIELD, "36")), BooleanClause.Occur.SHOULD);

            IndexReader reader = DirectoryReader.Open(directory);
            IndexSearcher indexSearcher = NewSearcher(reader);
            ScoreDoc[] hits = indexSearcher.Search(booleanQuery, filter, 1000).ScoreDocs;
            Assert.AreEqual(1, hits.Length, "Number of matched documents");
            reader.Dispose();
        }
开发者ID:WakeflyCBass,项目名称:lucenenet,代码行数:23,代码来源:TestFilteredSearch.cs

示例4: TestCustomMergeScheduler

 public void TestCustomMergeScheduler()
 {
     // we don't really need to execute anything, just to make sure the custom MS
     // compiles. But ensure that it can be used as well, e.g., no other hidden
     // dependencies or something. Therefore, don't use any random API !
     Directory dir = new RAMDirectory();
     IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT, null);
     conf.SetMergeScheduler(new ReportingMergeScheduler());
     IndexWriter writer = new IndexWriter(dir, conf);
     writer.AddDocument(new Document());
     writer.Commit(); // trigger flush
     writer.AddDocument(new Document());
     writer.Commit(); // trigger flush
     writer.ForceMerge(1);
     writer.Dispose();
     dir.Dispose();
 }
开发者ID:WakeflyCBass,项目名称:lucenenet,代码行数:17,代码来源:TestMergeSchedulerExternal.cs

示例5: TestEmptyIndex

 public virtual void TestEmptyIndex()
 {
     Directory dir = NewDirectory();
     IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetMaxBufferedDocs(500));
     writer.Dispose();
     IndexReader r = DirectoryReader.Open(dir);
     AtomicReader reader = SlowCompositeReaderWrapper.Wrap(r);
     FieldCache_Fields.DEFAULT.GetTerms(reader, "foobar", true);
     FieldCache_Fields.DEFAULT.GetTermsIndex(reader, "foobar");
     FieldCache_Fields.DEFAULT.PurgeByCacheKey(reader.CoreCacheKey);
     r.Dispose();
     dir.Dispose();
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:13,代码来源:TestFieldCache.cs

示例6: TestDummy

 public virtual void TestDummy()
 {
     MockDirectoryWrapper dir = NewMockDirectory();
       dir.AssertNoUnrefencedFilesOnClose = true;
       IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(LuceneTestCase.TEST_VERSION_CURRENT, null));
       iw.AddDocument(new Document());
       iw.Dispose();
       IndexOutput output = dir.CreateOutput("_hello.world", IOContext.DEFAULT);
       output.writeString("i am unreferenced!");
       output.Dispose();
       dir.Sync(CollectionsHelper.Singleton("_hello.world"));
       dir.Dispose();
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:13,代码来源:TestFailIfUnreferencedFiles.cs

示例7: TearDown

 public override void TearDown()
 {
     Iw.Dispose();
     TestUtil.CheckIndex(Dir); // for some extra coverage, checkIndex before we forceMerge
     Iwc.SetOpenMode(IndexWriterConfig.OpenMode_e.APPEND);
     IndexWriter iw = new IndexWriter(Dir, (IndexWriterConfig)Iwc.Clone());
     iw.ForceMerge(1);
     iw.Dispose();
     Dir.Dispose(); // just force a checkindex for now
     base.TearDown();
 }
开发者ID:WakeflyCBass,项目名称:lucenenet,代码行数:11,代码来源:TestBlockPostingsFormat2.cs

示例8: DoTestZeroPosIncrSloppy

        private void DoTestZeroPosIncrSloppy(Query q, int nExpected)
        {
            Directory dir = NewDirectory(); // random dir
            IndexWriterConfig cfg = NewIndexWriterConfig(TEST_VERSION_CURRENT, null);
            IndexWriter writer = new IndexWriter(dir, cfg);
            Document doc = new Document();
            doc.Add(new TextField("field", new CannedTokenStream(INCR_0_DOC_TOKENS)));
            writer.AddDocument(doc);
            IndexReader r = DirectoryReader.Open(writer, false);
            writer.Dispose();
            IndexSearcher s = NewSearcher(r);

            if (VERBOSE)
            {
                Console.WriteLine("QUERY=" + q);
            }

            TopDocs hits = s.Search(q, 1);
            Assert.AreEqual(nExpected, hits.TotalHits, "wrong number of results");

            if (VERBOSE)
            {
                for (int hit = 0; hit < hits.TotalHits; hit++)
                {
                    ScoreDoc sd = hits.ScoreDocs[hit];
                    Console.WriteLine("  hit doc=" + sd.Doc + " score=" + sd.Score);
                }
            }

            r.Dispose();
            dir.Dispose();
        }
开发者ID:WakeflyCBass,项目名称:lucenenet,代码行数:32,代码来源:TestMultiPhraseQuery.cs

示例9: TestReferenceDecrementIllegally

        public virtual void TestReferenceDecrementIllegally([ValueSource(typeof(ConcurrentMergeSchedulers), "Values")]IConcurrentMergeScheduler scheduler)
        {
            Directory dir = NewDirectory();
            var config = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))
                            .SetMergeScheduler(scheduler);
            IndexWriter writer = new IndexWriter(dir, config);
            SearcherManager sm = new SearcherManager(writer, false, new SearcherFactory());
            writer.AddDocument(new Document());
            writer.Commit();
            sm.MaybeRefreshBlocking();

            IndexSearcher acquire = sm.Acquire();
            IndexSearcher acquire2 = sm.Acquire();
            sm.Release(acquire);
            sm.Release(acquire2);

            acquire = sm.Acquire();
            acquire.IndexReader.DecRef();
            sm.Release(acquire);

            Assert.Throws<InvalidOperationException>(() => sm.Acquire(), "acquire should have thrown an InvalidOperationException since we modified the refCount outside of the manager");

            // sm.Dispose(); -- already closed
            writer.Dispose();
            dir.Dispose();
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:26,代码来源:TestSearcherManager.cs

示例10: TestReferenceDecrementIllegally

        public virtual void TestReferenceDecrementIllegally()
        {
            Directory dir = NewDirectory();
            IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetMergeScheduler(new ConcurrentMergeScheduler()));
            SearcherManager sm = new SearcherManager(writer, false, new SearcherFactory());
            writer.AddDocument(new Document());
            writer.Commit();
            sm.MaybeRefreshBlocking();

            IndexSearcher acquire = sm.Acquire();
            IndexSearcher acquire2 = sm.Acquire();
            sm.Release(acquire);
            sm.Release(acquire2);

            acquire = sm.Acquire();
            acquire.IndexReader.DecRef();
            sm.Release(acquire);
            try
            {
                sm.Acquire();
                Assert.Fail("acquire should have thrown an InvalidOperationException since we modified the refCount outside of the manager");
            }
            catch (InvalidOperationException ex)
            {
                //
            }

            // sm.Dispose(); -- already closed
            writer.Dispose();
            dir.Dispose();
        }
开发者ID:WakeflyCBass,项目名称:lucenenet,代码行数:31,代码来源:TestSearcherManager.cs

示例11: SetUp

        public override void SetUp()
        {
            base.SetUp();
            //IndexDir = CreateTempDir("RAMDirIndex");
            string tempDir = Path.GetTempPath();
            if (tempDir == null)
                throw new IOException("java.io.tmpdir undefined, cannot run test");
            IndexDir = new DirectoryInfo(Path.Combine(tempDir, "RAMDirIndex"));

            Directory dir = NewFSDirectory(IndexDir);
            IndexWriter writer = new IndexWriter(dir, (new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))).SetOpenMode(IndexWriterConfig.OpenMode_e.CREATE));
            // add some documents
            Document doc = null;
            for (int i = 0; i < DocsToAdd; i++)
            {
                doc = new Document();
                doc.Add(NewStringField("content", English.IntToEnglish(i).Trim(), Field.Store.YES));
                writer.AddDocument(doc);
            }
            Assert.AreEqual(DocsToAdd, writer.MaxDoc);
            writer.Dispose();
            dir.Dispose();
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:23,代码来源:TestRAMDirectory.cs

示例12: TestRAMDirectorySize

        public virtual void TestRAMDirectorySize()
        {
            Directory dir = NewFSDirectory(IndexDir);
            MockDirectoryWrapper ramDir = new MockDirectoryWrapper(Random(), new RAMDirectory(dir, NewIOContext(Random())));
            dir.Dispose();

            IndexWriter writer = new IndexWriter(ramDir, (new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))).SetOpenMode(IndexWriterConfig.OpenMode_e.APPEND));
            writer.ForceMerge(1);

            Assert.AreEqual(ramDir.SizeInBytes(), ramDir.RecomputedSizeInBytes);

            ThreadClass[] threads = new ThreadClass[NumThreads];
            for (int i = 0; i < NumThreads; i++)
            {
                int num = i;
                threads[i] = new ThreadAnonymousInnerClassHelper(this, writer, num);
            }
            for (int i = 0; i < NumThreads; i++)
            {
                threads[i].Start();
            }
            for (int i = 0; i < NumThreads; i++)
            {
                threads[i].Join();
            }

            writer.ForceMerge(1);
            Assert.AreEqual(ramDir.SizeInBytes(), ramDir.RecomputedSizeInBytes);

            writer.Dispose();
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:31,代码来源:TestRAMDirectory.cs

示例13: TestCustomLockFactory

        public virtual void TestCustomLockFactory()
        {
            Directory dir = new MockDirectoryWrapper(Random(), new RAMDirectory());
            MockLockFactory lf = new MockLockFactory(this);
            dir.LockFactory = lf;

            // Lock prefix should have been set:
            Assert.IsTrue(lf.LockPrefixSet, "lock prefix was not set by the RAMDirectory");

            IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())));

            // add 100 documents (so that commit lock is used)
            for (int i = 0; i < 100; i++)
            {
                AddDoc(writer);
            }

            // Both write lock and commit lock should have been created:
            Assert.AreEqual(1, lf.LocksCreated.Count, "# of unique locks created (after instantiating IndexWriter)");
            Assert.IsTrue(lf.MakeLockCount >= 1, "# calls to makeLock is 0 (after instantiating IndexWriter)");

            foreach (String lockName in lf.LocksCreated.Keys)
            {
                MockLockFactory.MockLock @lock = (MockLockFactory.MockLock)lf.LocksCreated[lockName];
                Assert.IsTrue(@lock.LockAttempts > 0, "# calls to Lock.obtain is 0 (after instantiating IndexWriter)");
            }

            writer.Dispose();
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:29,代码来源:TestLockFactory.cs

示例14: Run

 public override void Run()
 {
     IndexWriter writer = null;
     for (int i = 0; i < this.NumIteration; i++)
     {
         try
         {
             writer = new IndexWriter(Dir, (new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))).SetOpenMode(IndexWriterConfig.OpenMode_e.APPEND));
         }
         catch (IOException e)
         {
             if (e.ToString().IndexOf(" timed out:") == -1)
             {
                 HitException = true;
                 Console.WriteLine("Stress Test Index Writer: creation hit unexpected IOException: " + e.ToString());
                 Console.Out.Write(e.StackTrace);
             }
             else
             {
                 // lock obtain timed out
                 // NOTE: we should at some point
                 // consider this a failure?  The lock
                 // obtains, across IndexReader &
                 // IndexWriters should be "fair" (ie
                 // FIFO).
             }
         }
         catch (Exception e)
         {
             HitException = true;
             Console.WriteLine("Stress Test Index Writer: creation hit unexpected exception: " + e.ToString());
             Console.Out.Write(e.StackTrace);
             break;
         }
         if (writer != null)
         {
             try
             {
                 OuterInstance.AddDoc(writer);
             }
             catch (IOException e)
             {
                 HitException = true;
                 Console.WriteLine("Stress Test Index Writer: addDoc hit unexpected exception: " + e.ToString());
                 Console.Out.Write(e.StackTrace);
                 break;
             }
             try
             {
                 writer.Dispose();
             }
             catch (IOException e)
             {
                 HitException = true;
                 Console.WriteLine("Stress Test Index Writer: close hit unexpected exception: " + e.ToString());
                 Console.Out.Write(e.StackTrace);
                 break;
             }
             writer = null;
         }
     }
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:62,代码来源:TestLockFactory.cs

示例15: _testStressLocks

        public virtual void _testStressLocks(LockFactory lockFactory, DirectoryInfo indexDir)
        {
            Directory dir = NewFSDirectory(indexDir, lockFactory);

            // First create a 1 doc index:
            IndexWriter w = new IndexWriter(dir, (new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))).SetOpenMode(IndexWriterConfig.OpenMode_e.CREATE));
            AddDoc(w);
            w.Dispose();

            WriterThread writer = new WriterThread(this, 100, dir);
            SearcherThread searcher = new SearcherThread(this, 100, dir);
            writer.Start();
            searcher.Start();

            while (writer.IsAlive || searcher.IsAlive)
            {
                Thread.Sleep(1000);
            }

            Assert.IsTrue(!writer.HitException, "IndexWriter hit unexpected exceptions");
            Assert.IsTrue(!searcher.HitException, "IndexSearcher hit unexpected exceptions");

            dir.Dispose();
            // Cleanup
            System.IO.Directory.Delete(indexDir.FullName, true);
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:26,代码来源:TestLockFactory.cs


注:本文中的Lucene.Net.Index.IndexWriter.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。