Lucene.Net.Index.IndexWriter.Dispose C# (CSharp) Method

Dispose() protected method

protected Dispose ( bool disposing, bool waitForMerges ) : void
disposing bool
waitForMerges bool
return void
        protected virtual void Dispose(bool disposing, bool waitForMerges)
        {
            if (disposing)
            {
                // Ensure that only one thread actually gets to do the closing:
                if (ShouldClose())
                {
                    // If any methods have hit OutOfMemoryError, then abort
                    // on close, in case the internal state of IndexWriter
                    // or DocumentsWriter is corrupt
                    if (hitOOM)
                        RollbackInternal();
                    else
                        CloseInternal(waitForMerges);
                }
            }
        }
		

Same methods

IndexWriter::Dispose ( ) : void
IndexWriter::Dispose ( bool waitForMerges ) : void

Usage Example

        public static void CreateIndexCreative(Creative entity, string IndexPath)
        {
            var document = new Document();
            document.Add(new Field("CreativeId", entity.Creativeid.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            document.Add(new Field("Title", entity.Title, Field.Store.YES, Field.Index.ANALYZED));
            if (!string.IsNullOrEmpty(entity.About))
            {
                document.Add(new Field("About", entity.About, Field.Store.YES, Field.Index.ANALYZED));
            }

            Directory directory = FSDirectory.Open(new DirectoryInfo(IndexPath));
              Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30);

               var writer = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);

              try
              {

            writer.AddDocument(document);

            writer.Optimize();

            writer.Dispose();
              }
             finally
              {

              writer.Dispose();
              }
        }
All Usage Examples Of Lucene.Net.Index.IndexWriter::Dispose
IndexWriter