public IndexReader(IIndex index, bool openReadOnly)
        {
            if (index == null)
                throw new ArgumentNullException("index", "index cannot be null");
            this.index = index;
            this.isReadOnly = openReadOnly;
            this.isDisposed = false;
            switch (index.IndexStructure) {
                case IndexType.SingleIndex:
                    var singleIndex = (IIndex)index;
                    if (!singleIndex.HasIndexFiles())
                        throw new InvalidOperationException("There are no index files in the specified directory " + index.IndexDirectory.FullName);
                    this.luceneDirectory = singleIndex.GetLuceneDirectory();
                    break;
                case IndexType.DoubleIndex:
                case IndexType.CyclicalIndex:
                    var doubleIndex = (DoubleIndex)index;
                    if (!doubleIndex.HasIndexFiles())
                        throw new InvalidOperationException("There are no index files in the specified directory " + index.IndexDirectory.FullName);
                    this.luceneDirectory = doubleIndex.GetLuceneDirectory();
                    break;
                default:
                    throw new NotSupportedException(index.IndexStructure.ToString() + " not supported");
            }

            this.luceneReader = Lucene29.Net.Index.IndexReader.Open(this.luceneDirectory, openReadOnly);
        }
Example #2
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     if (this.isDisposed)
     {
         return;
     }
     if (this.luceneReader != null)
     {
         this.luceneReader.Close();
         this.luceneReader = null;
     }
     if (this.luceneDirectory != null)
     {
         this.luceneDirectory.Close();
         this.luceneDirectory = null;
     }
     this.isDisposed = true;
 }
Example #3
0
        public IndexReader(IIndex index, bool openReadOnly)
        {
            if (index == null)
            {
                throw new ArgumentNullException("index", "index cannot be null");
            }
            this.index      = index;
            this.isReadOnly = openReadOnly;
            this.isDisposed = false;
            switch (index.IndexStructure)
            {
            case IndexType.SingleIndex:
                var singleIndex = (IIndex)index;
                if (!singleIndex.HasIndexFiles())
                {
                    throw new InvalidOperationException("There are no index files in the specified directory " + index.IndexDirectory.FullName);
                }
                this.luceneDirectory = singleIndex.GetLuceneDirectory();
                break;

            case IndexType.DoubleIndex:
            case IndexType.CyclicalIndex:
                var doubleIndex = (DoubleIndex)index;
                if (!doubleIndex.HasIndexFiles())
                {
                    throw new InvalidOperationException("There are no index files in the specified directory " + index.IndexDirectory.FullName);
                }
                this.luceneDirectory = doubleIndex.GetLuceneDirectory();
                break;

            default:
                throw new NotSupportedException(index.IndexStructure.ToString() + " not supported");
            }

            this.luceneReader = Lucene29.Net.Index.IndexReader.Open(this.luceneDirectory, openReadOnly);
        }
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     if (this.isDisposed)
         return;
     if (this.luceneReader != null) {
         this.luceneReader.Close();
         this.luceneReader = null;
     }
     if (this.luceneDirectory != null) {
         this.luceneDirectory.Close();
         this.luceneDirectory = null;
     }
     this.isDisposed = true;
 }