Merge

Merge(Index, MergeOptions)

Merges the specified index into the current index. Note that the other index will not be changed.

public void Merge(Index index, MergeOptions options)
Parameter Type Description
index Index The index to merge into the current index.
options MergeOptions The merge options.

Exceptions

exception condition
ArgumentNullException The index or the merge options are null.
InvalidOperationException The other index contains documents and divides their text into terms differently from the current index.
ObjectDisposedException The index is disposed.

Remarks

If the other index has a previous version, it must be updated before merging with IndexUpdater.

The indexes have to divide the text of documents into terms in the same way: a search finds a document reliably only if the document was indexed with the dictionaries and settings that the index uses. The operation compares the current index with the other index if it contains documents: the settings UseStopWords, UseCharacterReplacements, ReplaceUnpairedSurrogates and SkipBlendedOnlyTerms, the alphabet, the tokenization dictionary, the stop word dictionary if the indexes use stop words, and the character replacement dictionary if the indexes use character replacements. If a difference is found, the operation throws InvalidOperationException and no index is changed.

The alphabet, the tokenization dictionary, the stop word dictionary and the character replacement dictionary of the current index are not changed by the operation. The other dictionaries of the other index are merged into the dictionaries of the current index.

Examples

The example demonstrates how to merge an index into the current index.

string indexFolder1 = @"c:\MyIndex1\";
string indexFolder2 = @"c:\MyIndex2\";
string documentsFolder1 = @"c:\MyDocuments1\";
string documentsFolder2 = @"c:\MyDocuments2\";

Index index1 = new Index(indexFolder1); // Creating index1
index1.Add(documentsFolder1); // Indexing documents

Index index2 = new Index(indexFolder2); // Creating index2
index2.Add(documentsFolder2); // Indexing documents

MergeOptions options = new MergeOptions();
options.Cancellation = new Cancellation(); // Creating cancellation object

// Merging index2 into index1. Note that index2 files will not be changed.
index1.Merge(index2, options);

See Also


Merge(IndexRepository, MergeOptions)

Merges indexes from the specified index repository into the current index. Note that indexes in the repository will not be changed.

public void Merge(IndexRepository repository, MergeOptions options)
Parameter Type Description
repository IndexRepository The index repository to merge into the current index.
options MergeOptions The merge options.

Exceptions

exception condition
ArgumentNullException The repository or the merge options are null.
InvalidOperationException An index of the repository contains documents and divides their text into terms differently from the current index.
ObjectDisposedException The index is disposed.

Remarks

If other indexes have a previous version, they must be updated before merging with IndexUpdater.

The indexes have to divide the text of documents into terms in the same way: a search finds a document reliably only if the document was indexed with the dictionaries and settings that the index uses. The operation compares the current index with every index of the repository that contains documents: the settings UseStopWords, UseCharacterReplacements, ReplaceUnpairedSurrogates and SkipBlendedOnlyTerms, the alphabet, the tokenization dictionary, the stop word dictionary if the indexes use stop words, and the character replacement dictionary if the indexes use character replacements. If a difference is found, the operation throws InvalidOperationException and no index is changed.

The alphabet, the tokenization dictionary, the stop word dictionary and the character replacement dictionary of the current index are not changed by the operation. The other dictionaries of the other indexes are merged into the dictionaries of the current index.

Examples

The example demonstrates how to merge an index repository into the current index.

string indexFolder1 = @"c:\MyIndex1\";
string indexFolder2 = @"c:\MyIndex2\";
string indexFolder3 = @"c:\MyIndex3\";
string documentsFolder1 = @"c:\MyDocuments1\";
string documentsFolder2 = @"c:\MyDocuments2\";
string documentsFolder3 = @"c:\MyDocuments3\";

Index index1 = new Index(indexFolder1); // Creating index1
index1.Add(documentsFolder1); // Indexing documents

IndexRepository repository = new IndexRepository(); // Creating index repository

Index index2 = repository.Create(indexFolder2); // Creating index2
index2.Add(documentsFolder2); // Indexing documents

Index index3 = repository.Create(indexFolder3); // Creating index3
index3.Add(documentsFolder3); // Indexing documents

MergeOptions options = new MergeOptions();
options.Cancellation = new Cancellation(); // Creating cancellation object

// Merging all indexes in the index repository into index1. Note that index2 and index3 will not be changed.
index1.Merge(repository, options);

See Also