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


C# Store.MockRAMDirectory类代码示例

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


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

示例1: TestLucene

		public virtual void  TestLucene()
		{
			
			int num = 100;
			
			Directory indexA = new MockRAMDirectory();
			Directory indexB = new MockRAMDirectory();
			
			FillIndex(indexA, 0, num);
			bool fail = VerifyIndex(indexA, 0);
			if (fail)
			{
				Assert.Fail("Index a is invalid");
			}
			
			FillIndex(indexB, num, num);
			fail = VerifyIndex(indexB, num);
			if (fail)
			{
				Assert.Fail("Index b is invalid");
			}
			
			Directory merged = new MockRAMDirectory();
			
			IndexWriter writer = new IndexWriter(merged, new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
			writer.SetMergeFactor(2);
			
			writer.AddIndexes(new Directory[]{indexA, indexB});
			writer.Close();
			
			fail = VerifyIndex(merged, 0);
			merged.Close();
			
			Assert.IsFalse(fail, "The merged index is invalid");
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:35,代码来源:TestIndexWriterMerging.cs

示例2: TestNullOrSubScorer

		public virtual void  TestNullOrSubScorer()
		{
			Directory dir = new MockRAMDirectory();
			IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
			Document doc = new Document();
			doc.Add(new Field("field", "a b c d", Field.Store.NO, Field.Index.ANALYZED));
			w.AddDocument(doc);
			IndexReader r = w.GetReader();
			IndexSearcher s = new IndexSearcher(r);
			BooleanQuery q = new BooleanQuery();
			q.Add(new TermQuery(new Term("field", "a")), BooleanClause.Occur.SHOULD);
			
			// PhraseQuery w/ no terms added returns a null scorer
			PhraseQuery pq = new PhraseQuery();
			q.Add(pq, BooleanClause.Occur.SHOULD);
			Assert.AreEqual(1, s.Search(q, 10).TotalHits);
			
			// A required clause which returns null scorer should return null scorer to
			// IndexSearcher.
			q = new BooleanQuery();
			pq = new PhraseQuery();
			q.Add(new TermQuery(new Term("field", "a")), BooleanClause.Occur.SHOULD);
			q.Add(pq, BooleanClause.Occur.MUST);
			Assert.AreEqual(0, s.Search(q, 10).TotalHits);
			
			DisjunctionMaxQuery dmq = new DisjunctionMaxQuery(1.0f);
			dmq.Add(new TermQuery(new Term("field", "a")));
			dmq.Add(pq);
			Assert.AreEqual(1, s.Search(dmq, 10).TotalHits);
			
			r.Close();
			w.Close();
			dir.Close();
		}
开发者ID:Mpdreamz,项目名称:lucene.net,代码行数:34,代码来源:TestBooleanQuery.cs

示例3: TestNullOrSubScorer

        public virtual void  TestNullOrSubScorer()
        {
            Directory dir = new MockRAMDirectory();
            IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
            Document doc = new Document();
            doc.Add(new Field("field", "a b c d", Field.Store.NO, Field.Index.ANALYZED));
            w.AddDocument(doc);

            IndexReader r = w.GetReader();
            IndexSearcher s = new IndexSearcher(r);
            BooleanQuery q = new BooleanQuery();
            q.Add(new TermQuery(new Term("field", "a")), Occur.SHOULD);

            // LUCENE-2617: make sure that a term not in the index still contributes to the score via coord factor
            float score = s.Search(q, 10).MaxScore;
            Query subQuery = new TermQuery(new Term("field", "not_in_index"));
            subQuery.Boost = 0;
            q.Add(subQuery, Occur.SHOULD);
            float score2 = s.Search(q, 10).MaxScore;
            Assert.AreEqual(score * .5, score2, 1e-6);

            // LUCENE-2617: make sure that a clause not in the index still contributes to the score via coord factor
            BooleanQuery qq = (BooleanQuery)q.Clone();
            PhraseQuery phrase = new PhraseQuery();
            phrase.Add(new Term("field", "not_in_index"));
            phrase.Add(new Term("field", "another_not_in_index"));
            phrase.Boost = 0;
            qq.Add(phrase, Occur.SHOULD);
            score2 = s.Search(qq, 10).MaxScore;
            Assert.AreEqual(score * (1.0 / 3), score2, 1e-6);

            // now test BooleanScorer2
            subQuery = new TermQuery(new Term("field", "b"));
            subQuery.Boost = 0;
            q.Add(subQuery, Occur.MUST);
            score2 = s.Search(q, 10).MaxScore;
            Assert.AreEqual(score * (2.0 / 3), score2, 1e-6);

            // PhraseQuery w/ no terms added returns a null scorer
            PhraseQuery pq = new PhraseQuery();
            q.Add(pq, Occur.SHOULD);
            Assert.AreEqual(1, s.Search(q, 10).TotalHits);
            
            // A required clause which returns null scorer should return null scorer to
            // IndexSearcher.
            q = new BooleanQuery();
            pq = new PhraseQuery();
            q.Add(new TermQuery(new Term("field", "a")), Occur.SHOULD);
            q.Add(pq, Occur.MUST);
            Assert.AreEqual(0, s.Search(q, 10).TotalHits);
            
            DisjunctionMaxQuery dmq = new DisjunctionMaxQuery(1.0f);
            dmq.Add(new TermQuery(new Term("field", "a")));
            dmq.Add(pq);
            Assert.AreEqual(1, s.Search(dmq, 10).TotalHits);
            
            r.Close();
            w.Close();
            dir.Close();
        }
开发者ID:Nangal,项目名称:lucene.net,代码行数:60,代码来源:TestBooleanQuery.cs

示例4: TestLucene

 public virtual void  TestLucene()
 {
     
     int num = 100;
     
     Directory indexA = new MockRAMDirectory();
     Directory indexB = new MockRAMDirectory();
     
     FillIndex(indexA, 0, num);
     Assert.IsFalse(VerifyIndex(indexA, 0), "Index a is invalid");
     
     FillIndex(indexB, num, num);
     Assert.IsFalse(VerifyIndex(indexB, num), "Index b is invalid");
     
     Directory merged = new MockRAMDirectory();
     
     IndexWriter writer = new IndexWriter(merged, new StandardAnalyzer(Util.Version.LUCENE_CURRENT), true, IndexWriter.MaxFieldLength.LIMITED);
     writer.MergeFactor = 2;
     
     writer.AddIndexesNoOptimize(new []{indexA, indexB});
     writer.Optimize();
     writer.Close();
     
     var fail = VerifyIndex(merged, 0);
     merged.Close();
     
     Assert.IsFalse(fail, "The merged index is invalid");
 }
开发者ID:Nangal,项目名称:lucene.net,代码行数:28,代码来源:TestIndexWriterMerging.cs

示例5: Eval

			public override void Eval(MockRAMDirectory dir)
			{
				if (doFail)
				{
					System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace();
					foreach (System.Diagnostics.StackFrame f in st.GetFrames())
					{
						if ("DoFlush" == f.GetMethod().Name)
							throw new System.IO.IOException("now failing during flush");
					}
				}
			}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:12,代码来源:TestConcurrentMergeScheduler.cs

示例6: TestCommitUserData

		public virtual void  TestCommitUserData()
		{
			RAMDirectory d = new MockRAMDirectory();

            System.Collections.Generic.IDictionary<string, string> commitUserData = new System.Collections.Generic.Dictionary<string,string>();
			commitUserData["foo"] = "fighters";
			
			// set up writer
			IndexWriter writer = new IndexWriter(d, new StandardAnalyzer(Util.Version.LUCENE_CURRENT), true, IndexWriter.MaxFieldLength.LIMITED);
			writer.SetMaxBufferedDocs(2);
			for (int i = 0; i < 27; i++)
				AddDocumentWithFields(writer);
			writer.Close();
			
			IndexReader r = IndexReader.Open(d, false);
			r.DeleteDocument(5);
			r.Flush(commitUserData);
			r.Close();
			
			SegmentInfos sis = new SegmentInfos();
			sis.Read(d);
			IndexReader r2 = IndexReader.Open(d, false);
			IndexCommit c = r.IndexCommit;
			Assert.AreEqual(c.UserData, commitUserData);
			
			Assert.AreEqual(sis.GetCurrentSegmentFileName(), c.SegmentsFileName);
			
			Assert.IsTrue(c.Equals(r.IndexCommit));
			
			// Change the index
            writer = new IndexWriter(d, new StandardAnalyzer(Util.Version.LUCENE_CURRENT), false, IndexWriter.MaxFieldLength.LIMITED);
			writer.SetMaxBufferedDocs(2);
			for (int i = 0; i < 7; i++)
				AddDocumentWithFields(writer);
			writer.Close();
			
			IndexReader r3 = r2.Reopen();
			Assert.IsFalse(c.Equals(r3.IndexCommit));
			Assert.IsFalse(r2.IndexCommit.IsOptimized);
			r3.Close();

            writer = new IndexWriter(d, new StandardAnalyzer(Util.Version.LUCENE_CURRENT), false, IndexWriter.MaxFieldLength.LIMITED);
			writer.Optimize();
			writer.Close();
			
			r3 = r2.Reopen();
			Assert.IsTrue(r3.IndexCommit.IsOptimized);
			r2.Close();
			r3.Close();
			d.Close();
		}
开发者ID:raol,项目名称:lucene.net,代码行数:51,代码来源:TestIndexReader.cs

示例7: TestFlushExceptions

        public virtual void TestFlushExceptions()
        {
            MockRAMDirectory directory = new MockRAMDirectory();
            FailOnlyOnFlush failure = new FailOnlyOnFlush();
            directory.FailOn(failure);

            IndexWriter writer = new IndexWriter(directory, ANALYZER, true, IndexWriter.MaxFieldLength.UNLIMITED);
            ConcurrentMergeScheduler cms = new ConcurrentMergeScheduler();
            writer.SetMergeScheduler(cms);
            writer.SetMaxBufferedDocs(2);
            Document doc = new Document();
            Field idField = new Field("id", "", Field.Store.YES, Field.Index.NOT_ANALYZED);
            doc.Add(idField);
            int extraCount = 0;

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 20; j++)
                {
                    idField.SetValue(System.Convert.ToString(i*20 + j));
                    writer.AddDocument(doc);
                }

                while (true)
                {
                    // must cycle here because sometimes the merge flushes
                    // the doc we just added and so there's nothing to
                    // flush, and we don't hit the exception
                    writer.AddDocument(doc);
                    failure.SetDoFail();
                    try
                    {
                        writer.Flush(true, false, true);
                        if (failure.hitExc)
                            Assert.Fail("failed to hit IOException");
                        extraCount++;
                    }
                    catch (System.IO.IOException ioe)
                    {
                        failure.ClearDoFail();
                        break;
                    }
                }
            }

            writer.Close();
            IndexReader reader = IndexReader.Open(directory, true);
            Assert.AreEqual(200 + extraCount, reader.NumDocs());
            reader.Close();
            directory.Close();
        }
开发者ID:Nangal,项目名称:lucene.net,代码行数:51,代码来源:TestConcurrentMergeScheduler.cs

示例8: TestCloneNoChangesStillReadOnly

		public virtual void  TestCloneNoChangesStillReadOnly()
		{
			Directory dir1 = new MockRAMDirectory();
			
			TestIndexReaderReopen.CreateIndex(dir1, true);
			IndexReader r1 = IndexReader.Open(dir1, false);
			IndexReader r2 = r1.Clone(false);

            Assert.IsTrue(DeleteWorked(1, r2), "deleting from the cloned should have worked");

			r1.Close();
			r2.Close();
			dir1.Close();
		}
开发者ID:synhershko,项目名称:lucene.net,代码行数:14,代码来源:TestIndexReaderClone.cs

示例9: TestCloneWriteToOrig

		public virtual void  TestCloneWriteToOrig()
		{
			Directory dir1 = new MockRAMDirectory();
			
			TestIndexReaderReopen.CreateIndex(dir1, true);
			IndexReader r1 = IndexReader.Open(dir1, false);
			IndexReader r2 = r1.Clone(false);

            Assert.IsTrue(DeleteWorked(1, r1), "deleting from the original should have worked");

			r1.Close();
			r2.Close();
			dir1.Close();
		}
开发者ID:synhershko,项目名称:lucene.net,代码行数:14,代码来源:TestIndexReaderClone.cs

示例10: TestCloneReadOnlySegmentReader

		public virtual void  TestCloneReadOnlySegmentReader()
		{
			Directory dir1 = new MockRAMDirectory();
			
			TestIndexReaderReopen.CreateIndex(dir1, false);
			IndexReader reader = IndexReader.Open(dir1, false);
			IndexReader readOnlyReader = reader.Clone(true);

            Assert.IsTrue(IsReadOnly(readOnlyReader), "reader isn't read only");
            Assert.IsFalse(DeleteWorked(1, readOnlyReader), "deleting from the original should not have worked");

			reader.Close();
			readOnlyReader.Close();
			dir1.Close();
		}
开发者ID:synhershko,项目名称:lucene.net,代码行数:15,代码来源:TestIndexReaderClone.cs

示例11: TestPrevTermAtEnd

		public virtual void  TestPrevTermAtEnd()
		{
			Directory dir = new MockRAMDirectory();
			IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
			AddDoc(writer, "aaa bbb");
			writer.Close();
			IndexReader reader = IndexReader.Open(dir);
			SegmentTermEnum termEnum = (SegmentTermEnum) reader.Terms();
			Assert.IsTrue(termEnum.Next());
			Assert.AreEqual("aaa", termEnum.Term().Text());
			Assert.IsTrue(termEnum.Next());
			Assert.AreEqual("aaa", termEnum.Prev().Text());
			Assert.AreEqual("bbb", termEnum.Term().Text());
			Assert.IsFalse(termEnum.Next());
			Assert.AreEqual("bbb", termEnum.Prev().Text());
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:16,代码来源:TestSegmentTermEnum.cs

示例12: Eval

			public override void  Eval(MockRAMDirectory dir)
			{
				if (doFail)
				{
					System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace();
					for (int i = 0; i < trace.FrameCount; i++)
					{
						System.Diagnostics.StackFrame sf = trace.GetFrame(i);
						if ("DoFlush".Equals(sf.GetMethod().Name))
						{
							//new RuntimeException().printStackTrace(System.out);
							throw new System.IO.IOException("now failing during flush");
						}
					}
				}
			}
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:16,代码来源:TestConcurrentMergeScheduler.cs

示例13: InitIndex

		private IndexWriter InitIndex(MockRAMDirectory dir)
		{
			dir.SetLockFactory(NoLockFactory.Instance);

            IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
			//writer.setMaxBufferedDocs(2);
			writer.SetMaxBufferedDocs(10);
			((ConcurrentMergeScheduler) writer.MergeScheduler).SetSuppressExceptions();
			
			Document doc = new Document();
			doc.Add(new Field("content", "aaa", Field.Store.YES, Field.Index.ANALYZED));
			doc.Add(new Field("id", "0", Field.Store.YES, Field.Index.ANALYZED));
			for (int i = 0; i < 157; i++)
				writer.AddDocument(doc);
			
			return writer;
		}
开发者ID:synhershko,项目名称:lucene.net,代码行数:17,代码来源:TestCrash.cs

示例14: Eval

 public override void  Eval(MockRAMDirectory dir)
 {
     if (doFail && !(Thread.CurrentThread.Name ?? "").Contains("Merge Thread"))
     {
         System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace();
         for (int i = 0; i < trace.FrameCount; i++)
         {
             System.Diagnostics.StackFrame sf = trace.GetFrame(i);
             if ("DoFlush".Equals(sf.GetMethod().Name))
             {
                 hitExc = true;
                 //Console.WriteLine(trace);
                 throw new System.IO.IOException("now failing during flush");
             }
         }
     }
 }
开发者ID:Nangal,项目名称:lucene.net,代码行数:17,代码来源:TestConcurrentMergeScheduler.cs

示例15: TestBinaryFieldInIndex

		public virtual void  TestBinaryFieldInIndex()
		{
			IFieldable binaryFldStored = new Field("binaryStored", System.Text.UTF8Encoding.UTF8.GetBytes(binaryValStored), Field.Store.YES);
			IFieldable stringFldStored = new Field("stringStored", binaryValStored, Field.Store.YES, Field.Index.NO, Field.TermVector.NO);
			
			// binary fields with store off are not allowed
            Assert.Throws<ArgumentException>(
                () => new Field("fail", System.Text.Encoding.UTF8.GetBytes(binaryValStored), Field.Store.NO));
			
			Document doc = new Document();
			
			doc.Add(binaryFldStored);
			
			doc.Add(stringFldStored);
			
			/** test for field count */
			Assert.AreEqual(2, doc.fields_ForNUnit.Count);
			
			/** add the doc to a ram index */
			MockRAMDirectory dir = new MockRAMDirectory();
			IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_CURRENT), true, IndexWriter.MaxFieldLength.LIMITED);
			writer.AddDocument(doc);
			writer.Close();
			
			/** open a reader and fetch the document */
			IndexReader reader = IndexReader.Open(dir, false);
			Document docFromReader = reader.Document(0);
			Assert.IsTrue(docFromReader != null);
			
			/** fetch the binary stored field and compare it's content with the original one */
			System.String binaryFldStoredTest = new System.String(System.Text.UTF8Encoding.UTF8.GetChars(docFromReader.GetBinaryValue("binaryStored")));
			Assert.IsTrue(binaryFldStoredTest.Equals(binaryValStored));
			
			/** fetch the string field and compare it's content with the original one */
			System.String stringFldStoredTest = docFromReader.Get("stringStored");
			Assert.IsTrue(stringFldStoredTest.Equals(binaryValStored));
			
			/** delete the document from index */
			reader.DeleteDocument(0);
			Assert.AreEqual(0, reader.NumDocs());
			
			reader.Close();
			dir.Close();
		}
开发者ID:synhershko,项目名称:lucene.net,代码行数:44,代码来源:TestBinaryDocument.cs


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