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:
Alphabet — the types of characters that define how text is divided into words.
Tokenization dictionary — the types of characters that define which words returned by a custom text segmenter are indexed.
Alias dictionary — the aliases that can be used in search queries.
Spelling corrector — the words with correct spelling used in spell checking.
Document passwords — the passwords of protected documents to be indexed.
Word forms provider — the provider of word forms used in search for different word forms.
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#
stringindexFolder=@"c:\MyIndex\";// Creating or opening an index in the specified folderIndexindex=newIndex(indexFolder);// Subscribing to the event that reports errors, including errors of exporting and importing dictionariesindex.Events.ErrorOccurred+=(sender,args)=>{Console.WriteLine("Error: "+args.Message);};// Exporting synonyms to a fileindex.Dictionaries.SynonymDictionary.ExportDictionary(@"c:\Synonyms.dat");// Importing synonyms from a file; if the file does not exist, the error is reported by the ErrorOccurred eventindex.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: