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


C# IndexWriter.Dispose方法代码示例

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


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

示例1: 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:joyanta,项目名称:lucene.net,代码行数:29,代码来源:TestLockFactory.cs

示例2: CreateDummySearcher

 // 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:paulirwin,项目名称:lucene.net,代码行数:12,代码来源:TestScorerPerf.cs

示例3: 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:paulirwin,项目名称:lucene.net,代码行数:11,代码来源:TestBlockPostingsFormat2.cs

示例4: TestFailIfIndexWriterNotClosed

 public virtual void TestFailIfIndexWriterNotClosed()
 {
     MockDirectoryWrapper dir = NewMockDirectory();
     IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, null));
     try
     {
         dir.Dispose();
         Assert.Fail();
     }
     catch (Exception expected)
     {
         Assert.IsTrue(expected.Message.Contains("there are still open locks"));
     }
     iw.Dispose();
     dir.Dispose();
 }
开发者ID:paulirwin,项目名称:lucene.net,代码行数:16,代码来源:TestMockDirectoryWrapper.cs

示例5: TestBasic

        public virtual void TestBasic()
        {
            HashSet<string> fileExtensions = new HashSet<string>();
            fileExtensions.Add(Lucene40StoredFieldsWriter.FIELDS_EXTENSION);
            fileExtensions.Add(Lucene40StoredFieldsWriter.FIELDS_INDEX_EXTENSION);

            MockDirectoryWrapper primaryDir = new MockDirectoryWrapper(Random(), new RAMDirectory());
            primaryDir.CheckIndexOnClose = false; // only part of an index
            MockDirectoryWrapper secondaryDir = new MockDirectoryWrapper(Random(), new RAMDirectory());
            secondaryDir.CheckIndexOnClose = false; // only part of an index

            FileSwitchDirectory fsd = new FileSwitchDirectory(fileExtensions, primaryDir, secondaryDir, true);
            // for now we wire Lucene40Codec because we rely upon its specific impl
            bool oldValue = OLD_FORMAT_IMPERSONATION_IS_ACTIVE;
            OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true;
            IndexWriter writer = new IndexWriter(fsd, (new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))).SetMergePolicy(NewLogMergePolicy(false)).SetCodec(Codec.ForName("Lucene40")).SetUseCompoundFile(false));
            TestIndexWriterReader.CreateIndexNoClose(true, "ram", writer);
            IndexReader reader = DirectoryReader.Open(writer, true);
            Assert.AreEqual(100, reader.MaxDoc);
            writer.Commit();
            // we should see only fdx,fdt files here
            string[] files = primaryDir.ListAll();
            Assert.IsTrue(files.Length > 0);
            for (int x = 0; x < files.Length; x++)
            {
                string ext = FileSwitchDirectory.GetExtension(files[x]);
                Assert.IsTrue(fileExtensions.Contains(ext));
            }
            files = secondaryDir.ListAll();
            Assert.IsTrue(files.Length > 0);
            // we should not see fdx,fdt files here
            for (int x = 0; x < files.Length; x++)
            {
                string ext = FileSwitchDirectory.GetExtension(files[x]);
                Assert.IsFalse(fileExtensions.Contains(ext));
            }
            reader.Dispose();
            writer.Dispose();

            files = fsd.ListAll();
            for (int i = 0; i < files.Length; i++)
            {
                Assert.IsNotNull(files[i]);
            }
            fsd.Dispose();
            OLD_FORMAT_IMPERSONATION_IS_ACTIVE = oldValue;
        }
开发者ID:paulirwin,项目名称:lucene.net,代码行数:47,代码来源:TestFileSwitchDirectory.cs

示例6: 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:paulirwin,项目名称:lucene.net,代码行数:19,代码来源:TestMultiThreadTermVectors.cs

示例7: 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:ChristopherHaws,项目名称:lucenenet,代码行数:23,代码来源:TestRAMDirectory.cs

示例8: IndexDictionary

		/// <summary> Index a Dictionary</summary>
		/// <param name="dict">the dictionary to index</param>
		/// <param name="mergeFactor">mergeFactor to use when indexing</param>
		/// <param name="ramMB">the max amount or memory in MB to use</param>
		/// <throws>  IOException </throws>
		/// <throws>AlreadyClosedException if the Spellchecker is already closed</throws>
		public virtual void IndexDictionary(IDictionary dict, int mergeFactor, int ramMB, CancellationToken token)
		{
			lock (modifyCurrentIndexLock)
			{
				EnsureOpen();
				Directory dir = this.spellindex;
				IndexWriter writer = new IndexWriter(spellindex, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
				writer.MergeFactor = mergeFactor;
				writer.SetMaxBufferedDocs(ramMB);

				System.Collections.IEnumerator iter = dict.GetWordsIterator();
				while (iter.MoveNext())
				{
					token.ThrowIfCancellationRequested();

					System.String word = (System.String)iter.Current;

					int len = word.Length;
					if (len < 3)
					{
						continue; // too short we bail but "too long" is fine...
					}

					if (this.Exist(word))
					{
						// if the word already exist in the gramindex
						continue;
					}

					// ok index the word
					Document doc = CreateDocument(word, GetMin(len), GetMax(len));
					writer.AddDocument(doc);
				}
				// close writer
				writer.Commit();
				writer.Dispose();
				// also re-open the spell index to see our own changes when the next suggestion
				// is fetched:
				SwapSearcher(dir);
			}
		}
开发者ID:GorelH,项目名称:ravendb,代码行数:47,代码来源:SpellChecker.cs

示例9: ClearIndex

		/// <summary>
		/// Removes all terms from the spell check index.
		/// </summary>
		public virtual void ClearIndex()
		{
			lock (modifyCurrentIndexLock)
			{
				EnsureOpen();
				Directory dir = this.spellindex;
				IndexWriter writer = new IndexWriter(dir, null, true, IndexWriter.MaxFieldLength.UNLIMITED);
				writer.Dispose();
				SwapSearcher(dir);
			}
		}
开发者ID:GorelH,项目名称:ravendb,代码行数:14,代码来源:SpellChecker.cs

示例10: SetSpellIndex

		/// <summary>
		/// Use a different index as the spell checker index or re-open
		/// the existing index if <code>spellIndex</code> is the same value
		/// as given in the constructor.
		/// </summary>
		/// <param name="spellIndexDir">spellIndexDir the spell directory to use </param>
		/// <throws>AlreadyClosedException if the Spellchecker is already closed</throws>
		/// <throws>IOException if spellchecker can not open the directory</throws>
		virtual public void SetSpellIndex(Directory spellIndexDir)
		{
			// this could be the same directory as the current spellIndex
			// modifications to the directory should be synchronized 
			lock (modifyCurrentIndexLock)
			{
				EnsureOpen();
				if (!IndexReader.IndexExists(spellIndexDir))
				{
					var writer = new IndexWriter(spellIndexDir, null, true,
						IndexWriter.MaxFieldLength.UNLIMITED);
					writer.Dispose();
				}
				SwapSearcher(spellIndexDir);
			}
		}
开发者ID:GorelH,项目名称:ravendb,代码行数:24,代码来源:SpellChecker.cs

示例11: 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:ChristopherHaws,项目名称:lucenenet,代码行数:31,代码来源:TestRAMDirectory.cs

示例12: TestRAMDirectoryNoLocking

        public virtual void TestRAMDirectoryNoLocking()
        {
            MockDirectoryWrapper dir = new MockDirectoryWrapper(Random(), new RAMDirectory());
            dir.LockFactory = NoLockFactory.DoNoLockFactory;
            dir.WrapLockFactory = false; // we are gonna explicitly test we get this back
            Assert.IsTrue(typeof(NoLockFactory).IsInstanceOfType(dir.LockFactory), "RAMDirectory.setLockFactory did not take");

            IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())));
            writer.Commit(); // required so the second open succeed
            // Create a 2nd IndexWriter.  this is normally not allowed but it should run through since we're not
            // using any locks:
            IndexWriter writer2 = null;
            try
            {
                writer2 = new IndexWriter(dir, (new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))).SetOpenMode(IndexWriterConfig.OpenMode_e.APPEND));
            }
            catch (Exception e)
            {
                Console.Out.Write(e.StackTrace);
                Assert.Fail("Should not have hit an IOException with no locking");
            }

            writer.Dispose();
            if (writer2 != null)
            {
                writer2.Dispose();
            }
        }
开发者ID:joyanta,项目名称:lucene.net,代码行数:28,代码来源:TestLockFactory.cs

示例13: 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:joyanta,项目名称:lucene.net,代码行数:62,代码来源:TestLockFactory.cs

示例14: TestMultiValuedField

 public virtual void TestMultiValuedField()
 {
     Directory indexStore = NewDirectory();
     IndexWriter writer = new IndexWriter(indexStore, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())));
     for (int i = 0; i < 5; i++)
     {
         Document doc = new Document();
         doc.Add(new StringField("string", "a" + i, Field.Store.NO));
         doc.Add(new StringField("string", "b" + i, Field.Store.NO));
         writer.AddDocument(doc);
     }
     writer.ForceMerge(1); // enforce one segment to have a higher unique term count in all cases
     writer.Dispose();
     Sort sort = new Sort(new SortField("string", SortField.Type_e.STRING), SortField.FIELD_DOC);
     // this should not throw AIOOBE or RuntimeEx
     IndexReader reader = DirectoryReader.Open(indexStore);
     IndexSearcher searcher = NewSearcher(reader);
     searcher.Search(new MatchAllDocsQuery(), null, 500, sort);
     reader.Dispose();
     indexStore.Dispose();
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:21,代码来源:TestSort.cs

示例15: TestEmptyStringVsNullStringSort

        public virtual void TestEmptyStringVsNullStringSort()
        {
            Directory dir = NewDirectory();
            IndexWriter w = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())));
            Document doc = new Document();
            doc.Add(NewStringField("f", "", Field.Store.NO));
            doc.Add(NewStringField("t", "1", Field.Store.NO));
            w.AddDocument(doc);
            w.Commit();
            doc = new Document();
            doc.Add(NewStringField("t", "1", Field.Store.NO));
            w.AddDocument(doc);

            IndexReader r = DirectoryReader.Open(w, true);
            w.Dispose();
            IndexSearcher s = NewSearcher(r);
            TopDocs hits = s.Search(new TermQuery(new Term("t", "1")), null, 10, new Sort(new SortField("f", SortField.Type_e.STRING)));
            Assert.AreEqual(2, hits.TotalHits);
            // null sorts first
            Assert.AreEqual(1, hits.ScoreDocs[0].Doc);
            Assert.AreEqual(0, hits.ScoreDocs[1].Doc);
            r.Dispose();
            dir.Dispose();
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:24,代码来源:TestSort.cs


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