Managing Dictionaries

Each index has a set of dictionaries that are used during indexing and searching. The dictionaries are available through the Dictionaries property of the Index class, which returns an instance of the DictionaryRepository class. The dictionaries of an index stored on disk are saved in the index folder, and every change of a dictionary is saved immediately.

The articles in this section describe the following dictionaries:

When dictionaries can be changed

The alphabet, the tokenization dictionary, the character replacements and the stop word dictionary, as well as the UseStopWords and UseCharacterReplacements index settings, define how the text of documents is divided into terms. Therefore, they can be changed only while the index contains no documents and is not performing an operation (its status is IndexStatus.Ready). Otherwise, a method or a property setter that changes them throws InvalidOperationException. A call that does not change the content of a dictionary or the value of a setting is allowed at any time. Configure these dictionaries and settings after creating a new index and before adding the first document. To use another content with documents that are already indexed, create a new index and index the documents again.

The synonym dictionary, the homophone dictionary, the alias dictionary, the spelling corrector and the document passwords can be changed at any time. The word forms provider can also be replaced at any time.

For more information on the dictionaries and settings that are fixed in an index, see the Index format and compatibility page.

Exporting and importing dictionaries

Each dictionary class is derived from the DictionaryBase class, which provides the ExportDictionary and ImportDictionary methods for saving the content of a dictionary to a file and loading it from a file.

These methods do not throw an exception if the file cannot be written or read, or if it has an invalid format. Instead, the error is reported by the ErrorOccurred event of the Index.Events object, and a dictionary of the index is not changed. However, the ImportDictionary method throws InvalidOperationException if the import would change a dictionary that cannot be changed in the index, as described above.

The following example demonstrates how to handle errors of exporting and importing dictionaries.

C#

string indexFolder = @"c:\MyIndex\";

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

// Subscribing to the event that reports errors, including errors of exporting and importing dictionaries
index.Events.ErrorOccurred += (sender, args) =>
{
    Console.WriteLine("Error: " + args.Message);
};

// Exporting synonyms to a file
index.Dictionaries.SynonymDictionary.ExportDictionary(@"c:\Synonyms.dat");

// Importing synonyms from a file; if the file does not exist, the error is reported by the ErrorOccurred event
index.Dictionaries.SynonymDictionary.ImportDictionary(@"c:\MissingFile.dat");

More resources

GitHub examples

You may easily run the code from documentation articles and see the features in action in our GitHub examples:

Free online document search App

Along with full featured .NET library we provide simple, but powerful free Apps.

You are welcome to search over your PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX and more with our free online Free Online Document Search App.

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.