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

Dispose() public method

Closes the index with or without waiting for currently running merges to finish. This is only meaningful when using a MergeScheduler that runs merges in background threads.

NOTE: if this method hits an OutOfMemoryError you should immediately close the writer, again. See above for details.

NOTE: it is dangerous to always call close(false), especially when IndexWriter is not open for very long, because this can result in "merge starvation" whereby long merges will never have a chance to finish. This will cause too many segments in your index over time.

public Dispose ( bool waitForMerges ) : void
waitForMerges bool if true, this call will block /// until all merges complete; else, it will ask all /// running merges to abort, wait until those merges have /// finished (which should be at most a few seconds), and /// then return. ///
return void
        public virtual void Dispose(bool waitForMerges)
        {
            Dispose(true, waitForMerges);
        }

Same methods

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

Usage Example

Ejemplo n.º 1
0
        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