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


C# SegmentReader.Close方法代码示例

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


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

示例1: TestTermDocs

		public virtual void  TestTermDocs()
		{
			try
			{
				//After adding the document, we should be able to read it back in
				SegmentReader reader = new SegmentReader(new SegmentInfo("test", 1, dir));
				Assert.IsTrue(reader != null);
				SegmentTermDocs segTermDocs = new SegmentTermDocs(reader);
				Assert.IsTrue(segTermDocs != null);
				segTermDocs.Seek(new Term(DocHelper.TEXT_FIELD_2_KEY, "Field"));
				if (segTermDocs.Next() == true)
				{
					int docId = segTermDocs.Doc();
					Assert.IsTrue(docId == 0);
					int freq = segTermDocs.Freq();
					Assert.IsTrue(freq == 3);
				}
				reader.Close();
			}
			catch (System.IO.IOException e)
			{
				Assert.IsTrue(false);
			}
		}
开发者ID:runefs,项目名称:Marvin,代码行数:24,代码来源:TestSegmentTermDocs.cs

示例2: PrintSegment

		internal static void  PrintSegment(System.String segment)
		{
			Directory directory = FSDirectory.GetDirectory("test", false);
			SegmentReader reader = new SegmentReader(new SegmentInfo(segment, 1, directory));
			
			for (int i = 0; i < reader.NumDocs(); i++)
			{
				System.Console.Out.WriteLine(reader.Document(i));
			}
			
			TermEnum tis = reader.Terms();
			while (tis.Next())
			{
				System.Console.Out.Write(tis.Term());
				System.Console.Out.WriteLine(" DF=" + tis.DocFreq());
				
				TermPositions positions = reader.TermPositions(tis.Term());
				try
				{
					while (positions.Next())
					{
						System.Console.Out.Write(" doc=" + positions.Doc());
						System.Console.Out.Write(" TF=" + positions.Freq());
						System.Console.Out.Write(" pos=");
						System.Console.Out.Write(positions.NextPosition());
						for (int j = 1; j < positions.Freq(); j++)
							System.Console.Out.Write("," + positions.NextPosition());
						System.Console.Out.WriteLine("");
					}
				}
				finally
				{
					positions.Close();
				}
			}
			tis.Close();
			reader.Close();
			directory.Close();
		}
开发者ID:runefs,项目名称:Marvin,代码行数:39,代码来源:DocTest.cs

示例3: Release

			/// <summary> Release the segment reader (i.e. decRef it and close if there
			/// are no more references.
			/// </summary>
			/// <param name="sr">
			/// </param>
			/// <throws>  IOException </throws>
			public virtual void  Release(SegmentReader sr, bool drop)
			{
				lock (this)
				{
					
					bool pooled = readerMap.Contains(sr.GetSegmentInfo());

                    System.Diagnostics.Debug.Assert(!pooled || readerMap[sr.GetSegmentInfo()] == sr);

                    // Drop caller's ref; for an external reader (not
                    // pooled), this decRef will close it
					sr.DecRef();
					
					if (pooled && (drop || (!Enclosing_Instance.poolReaders && sr.GetRefCount() == 1)))
					{

                        // We invoke deleter.checkpoint below, so we must be
                        // sync'd on IW if there are changes:
						
						// TODO: java 5
						// assert !sr.hasChanges || Thread.holdsLock(IndexWriter.this);

                        // Discard (don't save) changes when we are dropping
                        // the reader; this is used only on the sub-readers
                        // after a successful merge.
                        sr.hasChanges &= !drop;

                        bool hasChanges = sr.hasChanges;
						
						// Drop our ref -- this will commit any pending
						// changes to the dir
                        sr.Close();

                        // We are the last ref to this reader; since we're
                        // not pooling readers, we release it:
                        readerMap.Remove(sr.GetSegmentInfo());

                        if (hasChanges)
                        {
                            // Must checkpoint w/ deleter, because this
                            // segment reader will have created new _X_N.del
                            // file.
                            enclosingInstance.deleter.Checkpoint(enclosingInstance.segmentInfos, false);
                        }
					}
				}
			}
开发者ID:Mpdreamz,项目名称:lucene.net,代码行数:53,代码来源:IndexWriter.cs

示例4: Release

            /// <summary> Release the segment reader (i.e. decRef it and close if there
            /// are no more references.
            /// </summary>
            /// <param name="sr">
            /// </param>
            /// <throws>  IOException </throws>
            public virtual void Release(SegmentReader sr, bool drop)
            {
                lock (this)
                {

                    bool pooled = readerMap.Contains(sr.GetSegmentInfo());

                    System.Diagnostics.Debug.Assert(!pooled | readerMap[sr.GetSegmentInfo()] == sr);

                    // Drop caller's ref
                    sr.DecRef();

                    if (pooled && (drop || (!Enclosing_Instance.poolReaders && sr.GetRefCount() == 1)))
                    {

                        // We are the last ref to this reader; since we're
                        // not pooling readers, we release it:
                        readerMap.Remove(sr.GetSegmentInfo());

                        // TODO: java 5
                        // assert !sr.hasChanges || Thread.holdsLock(IndexWriter.this);

                        // Drop our ref -- this will commit any pending
                        // changes to the dir
                        bool success = false;
                        try
                        {
                            sr.Close();
                            success = true;
                        }
                        finally
                        {
                            if (!success && sr.hasChanges)
                            {
                                // Abandon the changes & retry closing:
                                sr.hasChanges = false;
                                try
                                {
                                    sr.Close();
                                }
                                catch (System.Exception ignore)
                                {
                                    // Keep throwing original exception
                                }
                            }
                        }
                    }
                }
            }
开发者ID:o0111,项目名称:ruralcafe,代码行数:55,代码来源:IndexWriter.cs

示例5: PrintSegment

		private void  PrintSegment(System.IO.StringWriter out_Renamed, System.String segment)
		{
			Directory directory = FSDirectory.GetDirectory(indexDir, false);
			SegmentReader reader = new SegmentReader(new SegmentInfo(segment, 1, directory));
			
			for (int i = 0; i < reader.NumDocs(); i++)
			{
				out_Renamed.WriteLine(reader.Document(i));
			}
			
			TermEnum tis = reader.Terms();
			while (tis.Next())
			{
				out_Renamed.Write(tis.Term());
				out_Renamed.WriteLine(" DF=" + tis.DocFreq());
				
				TermPositions positions = reader.TermPositions(tis.Term());
				try
				{
					while (positions.Next())
					{
						out_Renamed.Write(" doc=" + positions.Doc());
						out_Renamed.Write(" TF=" + positions.Freq());
                        out_Renamed.Write(" pos=");
                        out_Renamed.Write(positions.NextPosition());
						for (int j = 1; j < positions.Freq(); j++)
							out_Renamed.Write("," + positions.NextPosition());
						out_Renamed.WriteLine("");
					}
				}
				finally
				{
					positions.Close();
				}
			}
			tis.Close();
			reader.Close();
			directory.Close();
		}
开发者ID:runefs,项目名称:Marvin,代码行数:39,代码来源:TestDoc.cs

示例6: TestBadSeek

		public virtual void  TestBadSeek()
		{
			try
			{
				//After adding the document, we should be able to read it back in
				SegmentReader reader = new SegmentReader(new SegmentInfo("test", 3, dir));
				Assert.IsTrue(reader != null);
				SegmentTermDocs segTermDocs = new SegmentTermDocs(reader);
				Assert.IsTrue(segTermDocs != null);
				segTermDocs.Seek(new Term("textField2", "bad"));
				Assert.IsTrue(segTermDocs.Next() == false);
				reader.Close();
			}
			catch (System.IO.IOException e)
			{
				Assert.IsTrue(false);
			}
			try
			{
				//After adding the document, we should be able to read it back in
				SegmentReader reader = new SegmentReader(new SegmentInfo("test", 3, dir));
				Assert.IsTrue(reader != null);
				SegmentTermDocs segTermDocs = new SegmentTermDocs(reader);
				Assert.IsTrue(segTermDocs != null);
				segTermDocs.Seek(new Term("junk", "bad"));
				Assert.IsTrue(segTermDocs.Next() == false);
				reader.Close();
			}
			catch (System.IO.IOException e)
			{
				Assert.IsTrue(false);
			}
		}
开发者ID:runefs,项目名称:Marvin,代码行数:33,代码来源:TestSegmentTermDocs.cs


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