The SpellingCorrector class is designed to correct spelling errors in search queries, as well as to store words with correct spelling. You can learn about spelling correction in search queries on the Spell checking page.
The spelling corrector dictionary can be changed at any time, also in an index that contains documents.
To get the number of words in the spelling corrector dictionary, use the Count property.
To get an array of words contained in the spelling corrector dictionary, the GetWords method is used.
To add words to the spelling corrector dictionary, use the AddRange method.
The Clear method is used to remove all words from the spelling corrector dictionary.
To import words from a file, use the ImportDictionary method. Errors of exporting and importing are reported by the ErrorOccurred event of the index instead of exceptions.
The following example demonstrates the use of methods of the spelling corrector.
C#
stringindexFolder=@"c:\MyIndex\";// Creating or opening an index in the specified folderIndexindex=newIndex(indexFolder);if(index.Dictionaries.SpellingCorrector.Count>0){// Removing all words from the dictionaryindex.Dictionaries.SpellingCorrector.Clear();}// Adding words to the dictionarystring[]words=newstring[]{"achieve","accomplish","attain","reach"};index.Dictionaries.SpellingCorrector.AddRange(words);// Getting all words of the dictionarystring[]allWords=index.Dictionaries.SpellingCorrector.GetWords();Console.WriteLine("Words in the dictionary: "+allWords.Length);// Exporting words to a fileindex.Dictionaries.SpellingCorrector.ExportDictionary(@"c:\Words.txt");// Importing words from a fileindex.Dictionaries.SpellingCorrector.ImportDictionary(@"c:\Words.txt");
More resources
GitHub examples
You may easily run the code from documentation articles and see the features in action in our GitHub examples: