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


C# Lucene.Net.Store.RAMDirectory.DeleteFile方法代码示例

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


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

示例1: TestKeepLastNDeletionPolicyWithCreates

		public virtual void  TestKeepLastNDeletionPolicyWithCreates()
		{
			
			int N = 10;
			
			for (int pass = 0; pass < 4; pass++)
			{
				
				bool autoCommit = pass < 2;
				bool useCompoundFile = (pass % 2) > 0;
				
				KeepLastNDeletionPolicy policy = new KeepLastNDeletionPolicy(this, N);
				
				Directory dir = new RAMDirectory();
				IndexWriter writer = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), true, policy);
				writer.SetMaxBufferedDocs(10);
				writer.SetUseCompoundFile(useCompoundFile);
				writer.Close();
				Term searchTerm = new Term("content", "aaa");
				Query query = new TermQuery(searchTerm);
				
				for (int i = 0; i < N + 1; i++)
				{
					
					writer = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), false, policy);
					writer.SetMaxBufferedDocs(10);
					writer.SetUseCompoundFile(useCompoundFile);
					for (int j = 0; j < 17; j++)
					{
						AddDoc(writer);
					}
					// this is a commit when autoCommit=false:
					writer.Close();
					IndexReader reader = IndexReader.Open(dir, policy);
					reader.DeleteDocument(3);
					reader.SetNorm(5, "content", 2.0F);
					IndexSearcher searcher = new IndexSearcher(reader);
					Hits hits = searcher.Search(query);
					Assert.AreEqual(16, hits.Length());
					// this is a commit when autoCommit=false:
					reader.Close();
					searcher.Close();
					
					writer = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), true, policy);
					// This will not commit: there are no changes
					// pending because we opened for "create":
					writer.Close();
				}
				
				Assert.AreEqual(1 + 3 * (N + 1), policy.numOnInit);
				if (autoCommit)
				{
					Assert.IsTrue(policy.numOnCommit > 3 * (N + 1) - 1);
				}
				else
				{
					Assert.AreEqual(2 * (N + 1), policy.numOnCommit);
				}
				
				IndexSearcher searcher2 = new IndexSearcher(dir);
				Hits hits2 = searcher2.Search(query);
				Assert.AreEqual(0, hits2.Length());
				
				// Simplistic check: just verify only the past N segments_N's still
				// exist, and, I can open a reader on each:
				long gen = SegmentInfos.GetCurrentSegmentGeneration(dir);
				
				dir.DeleteFile(IndexFileNames.SEGMENTS_GEN);
				int expectedCount = 0;
				
				for (int i = 0; i < N + 1; i++)
				{
					try
					{
						IndexReader reader = IndexReader.Open(dir);
						
						// Work backwards in commits on what the expected
						// count should be.  Only check this in the
						// autoCommit false case:
						if (!autoCommit)
						{
							searcher2 = new IndexSearcher(reader);
							hits2 = searcher2.Search(query);
							Assert.AreEqual(expectedCount, hits2.Length());
							searcher2.Close();
							if (expectedCount == 0)
							{
								expectedCount = 16;
							}
							else if (expectedCount == 16)
							{
								expectedCount = 17;
							}
							else if (expectedCount == 17)
							{
								expectedCount = 0;
							}
						}
						reader.Close();
						if (i == N)
//.........这里部分代码省略.........
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:101,代码来源:TestDeletionPolicy.cs

示例2: TestKeepAllDeletionPolicy

		public virtual void  TestKeepAllDeletionPolicy()
		{
			
			for (int pass = 0; pass < 4; pass++)
			{
				
				bool autoCommit = pass < 2;
				bool useCompoundFile = (pass % 2) > 0;
				
				KeepAllDeletionPolicy policy = new KeepAllDeletionPolicy(this);
				
				Directory dir = new RAMDirectory();
				
				IndexWriter writer = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), true, policy);
				writer.SetMaxBufferedDocs(10);
				writer.SetUseCompoundFile(useCompoundFile);
				for (int i = 0; i < 107; i++)
				{
					AddDoc(writer);
				}
				writer.Close();
				
				writer = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), false, policy);
				writer.SetUseCompoundFile(useCompoundFile);
				writer.Optimize();
				writer.Close();
				
				Assert.AreEqual(2, policy.numOnInit);
				if (autoCommit)
				{
					Assert.IsTrue(policy.numOnCommit > 2);
				}
				else
				{
					// If we are not auto committing then there should
					// be exactly 2 commits (one per close above):
					Assert.AreEqual(2, policy.numOnCommit);
				}
				
				// Simplistic check: just verify all segments_N's still
				// exist, and, I can open a reader on each:
				dir.DeleteFile(IndexFileNames.SEGMENTS_GEN);
				long gen = SegmentInfos.GetCurrentSegmentGeneration(dir);
				while (gen > 0)
				{
					IndexReader reader = IndexReader.Open(dir);
					reader.Close();
					dir.DeleteFile(IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "", gen));
					gen--;
					
					if (gen > 0)
					{
						// Now that we've removed a commit point, which
						// should have orphan'd at least one index file.
						// Open & close a writer and assert that it
						// actually removed something:
						int preCount = dir.List().Length;
						writer = new IndexWriter(dir, false, new WhitespaceAnalyzer(), false, policy);
						writer.Close();
						int postCount = dir.List().Length;
						Assert.IsTrue(postCount < preCount);
					}
				}
				
				dir.Close();
			}
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:67,代码来源:TestDeletionPolicy.cs

示例3: TestKeepLastNDeletionPolicy

		public virtual void  TestKeepLastNDeletionPolicy()
		{
			
			int N = 5;
			
			for (int pass = 0; pass < 4; pass++)
			{
				
				bool autoCommit = pass < 2;
				bool useCompoundFile = (pass % 2) > 0;
				
				Directory dir = new RAMDirectory();
				
				KeepLastNDeletionPolicy policy = new KeepLastNDeletionPolicy(this, N);
				
				for (int j = 0; j < N + 1; j++)
				{
					IndexWriter writer = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), true, policy);
					writer.SetMaxBufferedDocs(10);
					writer.SetUseCompoundFile(useCompoundFile);
					for (int i = 0; i < 17; i++)
					{
						AddDoc(writer);
					}
					writer.Optimize();
					writer.Close();
				}
				
				Assert.IsTrue(policy.numDelete > 0);
				Assert.AreEqual(N + 1, policy.numOnInit);
				if (autoCommit)
				{
					Assert.IsTrue(policy.numOnCommit > 1);
				}
				else
				{
					Assert.AreEqual(N + 1, policy.numOnCommit);
				}
				
				// Simplistic check: just verify only the past N segments_N's still
				// exist, and, I can open a reader on each:
				dir.DeleteFile(IndexFileNames.SEGMENTS_GEN);
				long gen = SegmentInfos.GetCurrentSegmentGeneration(dir);
				for (int i = 0; i < N + 1; i++)
				{
					try
					{
						IndexReader reader = IndexReader.Open(dir);
						reader.Close();
						if (i == N)
						{
							Assert.Fail("should have failed on commits prior to last " + N);
						}
					}
					catch (System.IO.IOException e)
					{
						if (i != N)
						{
							throw e;
						}
					}
					if (i < N)
					{
						dir.DeleteFile(IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "", gen));
					}
					gen--;
				}
				
				dir.Close();
			}
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:71,代码来源:TestDeletionPolicy.cs

示例4: TestExpirationTimeDeletionPolicy

		public virtual void  TestExpirationTimeDeletionPolicy()
		{
			
			double SECONDS = 2.0;
			
			bool autoCommit = false;
			bool useCompoundFile = true;
			
			Directory dir = new RAMDirectory();
			ExpirationTimeDeletionPolicy policy = new ExpirationTimeDeletionPolicy(this, dir, SECONDS);
			IndexWriter writer = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), true, policy);
			writer.SetUseCompoundFile(useCompoundFile);
			writer.Close();
			
			long lastDeleteTime = 0;
			for (int i = 0; i < 7; i++)
			{
				// Record last time when writer performed deletes of
				// past commits
				lastDeleteTime = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
				writer = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), false, policy);
				writer.SetUseCompoundFile(useCompoundFile);
				for (int j = 0; j < 17; j++)
				{
					AddDoc(writer);
				}
				writer.Close();
				
				// Make sure to sleep long enough so that some commit
				// points will be deleted:
				System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * (int) (1000.0 * (SECONDS / 5.0))));
			}
			
			// First, make sure the policy in fact deleted something:
			Assert.IsTrue(policy.numDelete > 0, "no commits were deleted");
			
			// Then simplistic check: just verify that the
			// segments_N's that still exist are in fact within SECONDS
			// seconds of the last one's mod time, and, that I can
			// open a reader on each:
			long gen = SegmentInfos.GetCurrentSegmentGeneration(dir);
			
			System.String fileName = IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "", gen);
			dir.DeleteFile(IndexFileNames.SEGMENTS_GEN);
			while (gen > 0)
			{
				try
				{
					IndexReader reader = IndexReader.Open(dir);
					reader.Close();
					fileName = IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "", gen);
					long modTime = dir.FileModified(fileName);
					Assert.IsTrue(lastDeleteTime - modTime <= (SECONDS * 1000), "commit point was older than " + SECONDS + " seconds (" + (lastDeleteTime - modTime) + " msec) but did not get deleted");
				}
				catch (System.IO.IOException)
				{
					// OK
					break;
				}
				
				dir.DeleteFile(IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "", gen));
				gen--;
			}
			
			dir.Close();
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:66,代码来源:TestDeletionPolicy.cs

示例5: TestSimulatedCorruptIndex2

		public virtual void  TestSimulatedCorruptIndex2()
		{
			Directory dir = new RAMDirectory();
			
			IndexWriter writer = null;
			
			writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
			
			// add 100 documents
			for (int i = 0; i < 100; i++)
			{
				AddDoc(writer);
			}
			
			// close
			writer.Close();
			
			long gen = SegmentInfos.GetCurrentSegmentGeneration(dir);
			Assert.IsTrue(gen > 1, "segment generation should be > 1 but got " + gen);
			
			System.String[] files = dir.List();
			for (int i = 0; i < files.Length; i++)
			{
				if (files[i].EndsWith(".cfs"))
				{
					dir.DeleteFile(files[i]);
					break;
				}
			}
			
			IndexReader reader = null;
			try
			{
				reader = IndexReader.Open(dir);
				Assert.Fail("reader did not hit IOException on opening a corrupt index");
			}
			catch (System.Exception)
			{
			}
			if (reader != null)
			{
				reader.Close();
			}
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:44,代码来源:TestIndexWriter.cs

示例6: TestSimulatedCorruptIndex1

		public virtual void  TestSimulatedCorruptIndex1()
		{
			Directory dir = new RAMDirectory();
			
			IndexWriter writer = null;
			
			writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
			
			// add 100 documents
			for (int i = 0; i < 100; i++)
			{
				AddDoc(writer);
			}
			
			// close
			writer.Close();
			
			long gen = SegmentInfos.GetCurrentSegmentGeneration(dir);
			Assert.IsTrue(gen > 1, "segment generation should be > 1 but got " + gen);
			
			System.String fileNameIn = SegmentInfos.GetCurrentSegmentFileName(dir);
			System.String fileNameOut = IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "", 1 + gen);
			IndexInput in_Renamed = dir.OpenInput(fileNameIn);
			IndexOutput out_Renamed = dir.CreateOutput(fileNameOut);
			long length = in_Renamed.Length();
			for (int i = 0; i < length - 1; i++)
			{
				out_Renamed.WriteByte(in_Renamed.ReadByte());
			}
			in_Renamed.Close();
			out_Renamed.Close();
			dir.DeleteFile(fileNameIn);
			
			IndexReader reader = null;
			try
			{
				reader = IndexReader.Open(dir);
				Assert.Fail("reader did not hit IOException on opening a corrupt index");
			}
			catch (System.Exception)
			{
			}
			if (reader != null)
			{
				reader.Close();
			}
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:47,代码来源:TestIndexWriter.cs

示例7: TestKeepLastNDeletionPolicyWithReader

		public virtual void  TestKeepLastNDeletionPolicyWithReader()
		{
			
			int N = 10;
			
			for (int pass = 0; pass < 4; pass++)
			{
				
				bool autoCommit = pass < 2;
				bool useCompoundFile = (pass % 2) > 0;
				
				KeepLastNDeletionPolicy policy = new KeepLastNDeletionPolicy(this, N);
				
				Directory dir = new RAMDirectory();
				IndexWriter writer = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), true, policy);
				writer.SetUseCompoundFile(useCompoundFile);
				writer.Close();
				Term searchTerm = new Term("content", "aaa");
				Query query = new TermQuery(searchTerm);
				
				for (int i = 0; i < N + 1; i++)
				{
					writer = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), false, policy);
					writer.SetUseCompoundFile(useCompoundFile);
					for (int j = 0; j < 17; j++)
					{
						AddDoc(writer);
					}
					// this is a commit when autoCommit=false:
					writer.Close();
					IndexReader reader = IndexReader.Open(dir, policy);
					reader.DeleteDocument(3 * i + 1);
					reader.SetNorm(4 * i + 1, "content", 2.0F);
					IndexSearcher searcher = new IndexSearcher(reader);
					ScoreDoc[] hits = searcher.Search(query, null, 1000).scoreDocs;
					Assert.AreEqual(16 * (1 + i), hits.Length);
					// this is a commit when autoCommit=false:
					reader.Close();
					searcher.Close();
				}
				writer = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), false, policy);
				writer.SetUseCompoundFile(useCompoundFile);
				writer.Optimize();
				// this is a commit when autoCommit=false:
				writer.Close();
				
				Assert.AreEqual(2 * (N + 2), policy.numOnInit);
				if (!autoCommit)
					Assert.AreEqual(2 * (N + 2) - 1, policy.numOnCommit);
				
				IndexSearcher searcher2 = new IndexSearcher(dir);
				ScoreDoc[] hits2 = searcher2.Search(query, null, 1000).scoreDocs;
				Assert.AreEqual(176, hits2.Length);
				
				// Simplistic check: just verify only the past N segments_N's still
				// exist, and, I can open a reader on each:
				long gen = SegmentInfos.GetCurrentSegmentGeneration(dir);
				
				dir.DeleteFile(IndexFileNames.SEGMENTS_GEN);
				int expectedCount = 176;
				
				for (int i = 0; i < N + 1; i++)
				{
					try
					{
						IndexReader reader = IndexReader.Open(dir);
						
						// Work backwards in commits on what the expected
						// count should be.  Only check this in the
						// autoCommit false case:
						if (!autoCommit)
						{
							searcher2 = new IndexSearcher(reader);
							hits2 = searcher2.Search(query, null, 1000).scoreDocs;
							if (i > 1)
							{
								if (i % 2 == 0)
								{
									expectedCount += 1;
								}
								else
								{
									expectedCount -= 17;
								}
							}
							Assert.AreEqual(expectedCount, hits2.Length);
							searcher2.Close();
						}
						reader.Close();
						if (i == N)
						{
							Assert.Fail("should have failed on commits before last 5");
						}
					}
					catch (System.IO.IOException e)
					{
						if (i != N)
						{
							throw e;
						}
//.........这里部分代码省略.........
开发者ID:VirtueMe,项目名称:ravendb,代码行数:101,代码来源:TestDeletionPolicy.cs

示例8: TestKeepAllDeletionPolicy

		public virtual void  TestKeepAllDeletionPolicy()
		{
			
			for (int pass = 0; pass < 4; pass++)
			{
				
				bool autoCommit = pass < 2;
				bool useCompoundFile = (pass % 2) > 0;
				
				// Never deletes a commit
				KeepAllDeletionPolicy policy = new KeepAllDeletionPolicy(this);
				
				Directory dir = new RAMDirectory();
				policy.dir = dir;
				
				IndexWriter writer = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), true, policy);
				writer.SetMaxBufferedDocs(10);
				writer.SetUseCompoundFile(useCompoundFile);
				writer.SetMergeScheduler(new SerialMergeScheduler());
				for (int i = 0; i < 107; i++)
				{
					AddDoc(writer);
					if (autoCommit && i % 10 == 0)
						writer.Commit();
				}
				writer.Close();
				
				writer = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), false, policy);
				writer.SetUseCompoundFile(useCompoundFile);
				writer.Optimize();
				writer.Close();
				
				Assert.AreEqual(2, policy.numOnInit);
				if (!autoCommit)
				// If we are not auto committing then there should
				// be exactly 2 commits (one per close above):
					Assert.AreEqual(2, policy.numOnCommit);
				
				// Test listCommits
				System.Collections.ICollection commits = IndexReader.ListCommits(dir);
				if (!autoCommit)
				// 1 from opening writer + 2 from closing writer
					Assert.AreEqual(3, commits.Count);
				// 1 from opening writer + 2 from closing writer +
				// 11 from calling writer.commit() explicitly above
				else
					Assert.AreEqual(14, commits.Count);
				
				System.Collections.IEnumerator it = commits.GetEnumerator();
				// Make sure we can open a reader on each commit:
				while (it.MoveNext())
				{
					IndexCommit commit = (IndexCommit) it.Current;
					IndexReader r = IndexReader.Open(commit, null);
					r.Close();
				}
				
				// Simplistic check: just verify all segments_N's still
				// exist, and, I can open a reader on each:
				dir.DeleteFile(IndexFileNames.SEGMENTS_GEN);
				long gen = SegmentInfos.GetCurrentSegmentGeneration(dir);
				while (gen > 0)
				{
					IndexReader reader = IndexReader.Open(dir);
					reader.Close();
					dir.DeleteFile(IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "", gen));
					gen--;
					
					if (gen > 0)
					{
						// Now that we've removed a commit point, which
						// should have orphan'd at least one index file.
						// Open & close a writer and assert that it
						// actually removed something:
						int preCount = dir.ListAll().Length;
						writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false, policy, IndexWriter.MaxFieldLength.LIMITED);
						writer.Close();
						int postCount = dir.ListAll().Length;
						Assert.IsTrue(postCount < preCount);
					}
				}
				
				dir.Close();
			}
		}
开发者ID:VirtueMe,项目名称:ravendb,代码行数:85,代码来源:TestDeletionPolicy.cs


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