Beispiel #1
0
        public IndexWriter(IIndex index, AnalyzerType analyzer, bool create, bool allowUnlimitedFieldLength)
        {
            if (index == null)
            {
                throw new ArgumentNullException("index", "index cannot be null");
            }
            if (index.IndexStructure == IndexType.None)
            {
                throw new ArgumentException("The specified index structure cannot be None", "index");
            }
            if (analyzer == AnalyzerType.None || analyzer == AnalyzerType.Unknown)
            {
                throw new ArgumentException("The specified analyzer cannot be None or Unknown", "analyzer");
            }
            this.analyzer = TypeConverter.GetAnalyzer(analyzer);
            this.index    = index;

            DirectoryInfo writeDirectory = null;
            bool          hasIndexfiles  = GetIndexWriteDirectory(out writeDirectory);

            // you said append but there's no index files
            if (!create && !hasIndexfiles)
            {
                create = true;
            }

            this.openDirectory = Lucene29.Net.Store.FSDirectory.Open(writeDirectory);
            this.writer        = new Lucene29.Net.Index.IndexWriter(this.openDirectory, this.analyzer, create, (allowUnlimitedFieldLength) ? Lucene29.Net.Index.IndexWriter.MaxFieldLength.UNLIMITED : Lucene29.Net.Index.IndexWriter.MaxFieldLength.LIMITED);
        }
Beispiel #2
0
        /// <summary>
        /// Closes this index.
        /// </summary>
        public void Close()
        {
            // Flip that toggle switch
            //if (!string.IsNullOrEmpty(this.toggleFile)) IndexMap.HitTheJackalSwitch(this.toggleFile);
            if (this.writer != null)
            {
                this.writer.Close();
            }
            if (this.openDirectory != null)
            {
                this.openDirectory.Close();
            }
            this.writer        = null;
            this.openDirectory = null;

            this.index.Refresh();
            if (this.index.IndexStructure == IndexType.DoubleIndex)
            {
                ((IDoubleIndex)this.index).FlipToggleSwitch();
            }
            else if (this.index.IndexStructure == IndexType.CyclicalIndex)
            {
                ICyclicalIndex ci = (ICyclicalIndex)this.index;
                ci.CopyMirror();
                ci.FlipToggleSwitch();
            }

            this.isDisposed = true;
            LibraryAnalysis.Fire(new IndexInfo(this.index.IndexDirectory.Parent.FullName, this.index.IndexDirectory.Name, this.totalWrites, this.optimized, DateTime.Now));
        }