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


C# IndexReader.Reopen方法代码示例

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


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

示例1: RefreshReader

 private static IndexReader RefreshReader(IndexReader reader)
 {
     IndexReader oldReader = reader;
     reader = reader.Reopen();
     if (reader != oldReader)
     {
         oldReader.Close();
     }
     return reader;
 }
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:10,代码来源:TestCachingSpanFilter.cs

示例2: ValidateSearcher

        private void ValidateSearcher(bool forceReopen)
        {
            EnsureIndex();

            if (!forceReopen)
            {
                if (_reader == null)
                {
                    lock (_locker)
                    {
                        //double check
                        if (_reader == null)
                        {
                            try
                            {
                                //get a reader - could be NRT or based on directly depending on how this was constructed
                                _reader = _nrtWriter == null
                                    ? OpenNewReader()
                                    : _nrtWriter.GetReader();

                                _searcher = new IndexSearcher(_reader);
                            }
                            catch (IOException ex)
                            {
                                throw new ApplicationException("Could not create an index searcher with the supplied lucene directory", ex);
                            }
                        }
                    }
                }
                else
                {
                    switch (_reader.GetReaderStatus())
                    {
                        case ReaderStatus.Current:
                            break;
                        case ReaderStatus.Closed:
                            lock (_locker)
                            {
                                //get a reader - could be NRT or based on directly depending on how this was constructed
                                _reader = _nrtWriter == null
                                    ? OpenNewReader()
                                    : _nrtWriter.GetReader();

                                _searcher = new IndexSearcher(_reader);
                            }
                            break;
                        case ReaderStatus.NotCurrent:

                            lock (_locker)
                            {
                                //yes, this is actually the way the Lucene wants you to work...
                                //normally, i would have thought just calling Reopen() on the underlying reader would suffice... but it doesn't.
                                //here's references:
                                // http://stackoverflow.com/questions/1323779/lucene-indexreader-reopen-doesnt-seem-to-work-correctly
                                // http://gist.github.com/173978
                                //Also note that when a new reader is returned from Reopen() the old reader is not actually closed -
                                // but more importantly the old reader might still be in use from another thread! So we can't just
                                // close it here because that would cause a YSOD: Lucene.Net.Store.AlreadyClosedException: this IndexReader is closed
                                // since another thread might be using it. I'm 'hoping' that the GC will just take care of the left over reader's that might
                                // be currently being used in a search, otherwise there's really no way to now when it's safe to close the reader. A reader is
                                // IDisposable so I'm pretty sure the GC will do it's thing since there won't be any refs to it once it is done using it.

                                var newReader = _reader.Reopen();
                                if (newReader != _reader)
                                {
                                    //if it's changed, then re-assign, note: the above, before we used to close the old one here
                                    // but that will cause problems since the old reader might be in use on another thread.
                                    _reader = newReader;
                                    _searcher = new IndexSearcher(_reader);
                                }
                            }

                            break;
                    }

                }
            }
            else
            {
                if (_reader != null)
                {
                    lock (_locker)
                    {
                        //double check
                        if (_reader != null)
                        {
                            try
                            {
                                _searcher.Close();
                                _reader.Close();
                            }
                            catch (IOException ex)
                            {
                                //this will happen if it's already closed ( i think )
                                Trace.TraceError("Examine: error occurred closing index searcher. {0}", ex);
                            }
                            finally
                            {
                                //set to null in case another call to this method has passed the first lock and is checking for null
                                _searcher = null;
//.........这里部分代码省略.........
开发者ID:snowattitudes,项目名称:Examine,代码行数:101,代码来源:LuceneSearcher.cs

示例3: RefreshReader

		internal virtual ReaderCouple RefreshReader(IndexReader reader, TestReopen test, int modify, bool hasChanges)
		{
			lock (createReaderMutex)
			{
				IndexReader r = null;
				if (test != null)
				{
					test.ModifyIndex(modify);
					r = test.OpenReader();
				}
				
				IndexReader refreshed = null;
				try
				{
					refreshed = reader.Reopen();
				}
				finally
				{
					if (refreshed == null && r != null)
					{
						// Hit exception -- close opened reader
						r.Close();
					}
				}
				
				if (hasChanges)
				{
					if (refreshed == reader)
					{
						Assert.Fail("No new IndexReader instance created during refresh.");
					}
				}
				else
				{
					if (refreshed != reader)
					{
						Assert.Fail("New IndexReader instance created during refresh even though index had no changes.");
					}
				}
				
				return new ReaderCouple(r, refreshed);
			}
		}
开发者ID:Mpdreamz,项目名称:lucene.net,代码行数:43,代码来源:TestIndexReaderReopen.cs

示例4: RefreshReader

		private ReaderCouple RefreshReader(IndexReader reader, TestReopen_Renamed_Class test, int modify, bool hasChanges)
		{
			lock (createReaderMutex)
			{
				IndexReader r = null;
				if (test != null)
				{
					test.ModifyIndex(modify);
					r = test.OpenReader();
				}
				
				IndexReader refreshed = reader.Reopen();
				if (hasChanges)
				{
					if (refreshed == reader)
					{
						Assert.Fail("No new IndexReader instance created during refresh.");
					}
				}
				else
				{
					if (refreshed != reader)
					{
						Assert.Fail("New IndexReader instance created during refresh even though index had no changes.");
					}
				}
				
				return new ReaderCouple(r, refreshed);
			}
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:30,代码来源:TestIndexReaderReopen.cs


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