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


C# Lucene.Net.Documents.Document.GetField方法代码示例

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


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

示例1: TestMergeCompressedFields

		public virtual void  TestMergeCompressedFields()
		{
			System.IO.FileInfo indexDir = new System.IO.FileInfo(System.IO.Path.Combine(SupportClass.AppSettings.Get("tempDir", ""), "mergecompressedfields"));
			Directory dir = FSDirectory.Open(indexDir);
			try
			{
				for (int i = 0; i < 5; i++)
				{
					// Must make a new writer & doc each time, w/
					// different fields, so bulk merge of stored fields
					// cannot run:
					IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(), i == 0, IndexWriter.MaxFieldLength.UNLIMITED);
					try
					{
						w.SetMergeFactor(5);
						w.SetMergeScheduler(new SerialMergeScheduler());
						Document doc = new Document();
						doc.Add(new Field("test1", "this is some data that will be compressed this this this", Field.Store.COMPRESS, Field.Index.NO));
						doc.Add(new Field("test2", new byte[20], Field.Store.COMPRESS));
						doc.Add(new Field("field" + i, "random field", Field.Store.NO, Field.Index.ANALYZED));
						w.AddDocument(doc);
					}
					finally
					{
						w.Close();
					}
				}
				
				byte[] cmp = new byte[20];
				
				IndexReader r = IndexReader.Open(dir);
				try
				{
					for (int i = 0; i < 5; i++)
					{
						Document doc = r.Document(i);
						Assert.AreEqual(doc.GetField("test1").StringValue(), "this is some data that will be compressed this this this");
						byte[] b = doc.GetField("test2").BinaryValue();
                        Assert.AreEqual(b.Length, cmp.Length);
                        for (int j = 0; j < b.Length; j++)
                            Assert.AreEqual(b[j], cmp[j]);
					}
				}
				finally
				{
					r.Close();
				}
			}
			finally
			{
				dir.Close();
				_TestUtil.RmDir(indexDir);
			}
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:54,代码来源:TestIndexWriter.cs

示例2: TestIndexStoreCombos

		public virtual void  TestIndexStoreCombos()
		{
			MockRAMDirectory dir = new MockRAMDirectory();
			IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);
			byte[] b = new byte[50];
			for (int i = 0; i < 50; i++)
				b[i] = (byte) (i + 77);
			
			Document doc = new Document();
			Field f = new Field("binary", b, 10, 17, Field.Store.YES);
			f.SetTokenStream(new WhitespaceTokenizer(new System.IO.StringReader("doc1field1")));
			Field f2 = new Field("string", "value", Field.Store.YES, Field.Index.ANALYZED);
			f2.SetTokenStream(new WhitespaceTokenizer(new System.IO.StringReader("doc1field2")));
			doc.Add(f);
			doc.Add(f2);
			w.AddDocument(doc);
			
			// add 2 docs to test in-memory merging
			f.SetTokenStream(new WhitespaceTokenizer(new System.IO.StringReader("doc2field1")));
			f2.SetTokenStream(new WhitespaceTokenizer(new System.IO.StringReader("doc2field2")));
			w.AddDocument(doc);
			
			// force segment flush so we can force a segment merge with doc3 later.
			w.Commit();
			
			f.SetTokenStream(new WhitespaceTokenizer(new System.IO.StringReader("doc3field1")));
			f2.SetTokenStream(new WhitespaceTokenizer(new System.IO.StringReader("doc3field2")));
			
			w.AddDocument(doc);
			w.Commit();
			w.Optimize(); // force segment merge.
			
			IndexReader ir = IndexReader.Open(dir);
			doc = ir.Document(0);
			f = doc.GetField("binary");
			b = f.GetBinaryValue();
			Assert.IsTrue(b != null);
			Assert.AreEqual(17, b.Length, 17);
			Assert.AreEqual(87, b[0]);
			
			Assert.IsTrue(ir.Document(0).GetFieldable("binary").IsBinary());
			Assert.IsTrue(ir.Document(1).GetFieldable("binary").IsBinary());
			Assert.IsTrue(ir.Document(2).GetFieldable("binary").IsBinary());
			
			Assert.AreEqual("value", ir.Document(0).Get("string"));
			Assert.AreEqual("value", ir.Document(1).Get("string"));
			Assert.AreEqual("value", ir.Document(2).Get("string"));
			
			
			// test that the terms were indexed.
			Assert.IsTrue(ir.TermDocs(new Term("binary", "doc1field1")).Next());
			Assert.IsTrue(ir.TermDocs(new Term("binary", "doc2field1")).Next());
			Assert.IsTrue(ir.TermDocs(new Term("binary", "doc3field1")).Next());
			Assert.IsTrue(ir.TermDocs(new Term("string", "doc1field2")).Next());
			Assert.IsTrue(ir.TermDocs(new Term("string", "doc2field2")).Next());
			Assert.IsTrue(ir.TermDocs(new Term("string", "doc3field2")).Next());
			
			ir.Close();
			dir.Close();
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:60,代码来源:TestIndexWriter.cs

示例3: TestBinaryFieldOffsetLength

		public virtual void  TestBinaryFieldOffsetLength()
		{
			MockRAMDirectory dir = new MockRAMDirectory();
			IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);
			byte[] b = new byte[50];
			for (int i = 0; i < 50; i++)
				b[i] = (byte) (i + 77);
			
			Document doc = new Document();
			Field f = new Field("binary", b, 10, 17, Field.Store.YES);
			byte[] bx = f.GetBinaryValue();
			Assert.IsTrue(bx != null);
			Assert.AreEqual(50, bx.Length);
			Assert.AreEqual(10, f.GetBinaryOffset());
			Assert.AreEqual(17, f.GetBinaryLength());
			doc.Add(f);
			w.AddDocument(doc);
			w.Close();
			
			IndexReader ir = IndexReader.Open(dir);
			doc = ir.Document(0);
			f = doc.GetField("binary");
			b = f.GetBinaryValue();
			Assert.IsTrue(b != null);
			Assert.AreEqual(17, b.Length, 17);
			Assert.AreEqual(87, b[0]);
			ir.Close();
			dir.Close();
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:29,代码来源:TestIndexWriter.cs


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