Optimize

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.

public void Optimize()

Exceptions

exception condition
ObjectDisposedException The index is disposed.

Examples

The example demonstrates how to merge segments of an index.

string indexFolder = @"c:\MyIndex\";
string documentsFolder1 = @"c:\MyDocuments1\";
string documentsFolder2 = @"c:\MyDocuments2\";
string documentsFolder3 = @"c:\MyDocuments3\";

Index index = new Index(indexFolder); // Creating index in the specified folder

index.Add(documentsFolder1); // Indexing documents from the specified folder
index.Add(documentsFolder2); // Each call to Add creates at least one new segment in the index
index.Add(documentsFolder3);

// Merging segments of the index
index.Optimize();

See Also


Optimize(MergeOptions)

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.

public void Optimize(MergeOptions options)
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.

string indexFolder = @"c:\MyIndex\";
string documentsFolder1 = @"c:\MyDocuments1\";
string documentsFolder2 = @"c:\MyDocuments2\";
string documentsFolder3 = @"c:\MyDocuments3\";

Index index = new Index(indexFolder); // Creating index in the specified folder

index.Add(documentsFolder1); // Indexing documents from the specified folder
index.Add(documentsFolder2); // Each call to Add creates at least one new segment in the index
index.Add(documentsFolder3);

MergeOptions options = new MergeOptions();
options.IsAsync = true; // Asynchronous operation
options.Cancellation = new Cancellation(); // Creating cancellation object

// Merging segments of the index
index.Optimize(options); // This method will return before the operation is completed

options.Cancellation.CancelAfter(10000); // Setting maximum duration of the operation to 10 seconds

See Also