Пример #1
0
 /// <summary>
 /// Returns the indexReader.  NOTE: this returns a
 /// reference.  You must call IndexReader.DecRef() when
 /// you're done.
 /// </summary>
 public virtual DirectoryReader GetIndexReader()
 {
     lock (this)
     {
         if (indexReader != null)
         {
             indexReader.IncRef();
         }
         return(indexReader);
     }
 }
Пример #2
0
        /// <summary>
        /// Set the index reader. Takes ownership of that index reader, that is,
        /// internally performs indexReader.incRef() (If caller no longer needs that
        /// reader it should decRef()/close() it after calling this method, otherwise,
        /// the reader will remain open).
        /// </summary>
        /// <param name="indexReader">The indexReader to set.</param>
        public virtual void SetIndexReader(DirectoryReader indexReader)
        {
            lock (this)
            {
                if (indexReader == this.indexReader)
                {
                    return;
                }

                if (this.indexReader != null)
                {
                    // Release current IR
                    this.indexReader.DecRef();
                }

                this.indexReader = indexReader;
                if (indexReader != null)
                {
                    // Hold reference to new IR
                    indexReader.IncRef();
                    indexSearcher = new IndexSearcher(indexReader);
                }
                else
                {
                    indexSearcher = null;
                }
            }
        }