Minimizes the number of index segments by merging them one with another. This operation improves search performance and physically removes deleted documents from the index. A very large index is optimized into several segments of limited size.
publicvoidOptimize()
Exceptions
exception
condition
ObjectDisposedException
The index is disposed.
Examples
The example demonstrates how to merge segments of an index.
stringindexFolder=@"c:\MyIndex\";stringdocumentsFolder1=@"c:\MyDocuments1\";stringdocumentsFolder2=@"c:\MyDocuments2\";stringdocumentsFolder3=@"c:\MyDocuments3\";Indexindex=newIndex(indexFolder);// Creating index in the specified folderindex.Add(documentsFolder1);// Indexing documents from the specified folderindex.Add(documentsFolder2);// Each call to Add creates at least one new segment in the indexindex.Add(documentsFolder3);// Merging segments of the indexindex.Optimize();
Minimizes the number of index segments by merging them one with another. This operation improves search performance and physically removes deleted documents from the index. A very large index is optimized into several segments of limited size.
publicvoidOptimize(MergeOptionsoptions)
Parameter
Type
Description
options
MergeOptions
The merge options.
Exceptions
exception
condition
ArgumentNullException
The merge options are null.
ObjectDisposedException
The index is disposed.
Examples
The example demonstrates how to merge segments of an index with particular merge options.
stringindexFolder=@"c:\MyIndex\";stringdocumentsFolder1=@"c:\MyDocuments1\";stringdocumentsFolder2=@"c:\MyDocuments2\";stringdocumentsFolder3=@"c:\MyDocuments3\";Indexindex=newIndex(indexFolder);// Creating index in the specified folderindex.Add(documentsFolder1);// Indexing documents from the specified folderindex.Add(documentsFolder2);// Each call to Add creates at least one new segment in the indexindex.Add(documentsFolder3);MergeOptionsoptions=newMergeOptions();options.IsAsync=true;// Asynchronous operationoptions.Cancellation=newCancellation();// Creating cancellation object// Merging segments of the indexindex.Optimize(options);// This method will return before the operation is completedoptions.Cancellation.CancelAfter(10000);// Setting maximum duration of the operation to 10 seconds