During the search, a search query can be checked for spelling errors in words. To enable spelling correction in search queries, the Enabled property of the spelling corrector options is set to true. By default, the spelling correction is disabled.
The spelling corrector considers the following types of misprints: adding a character, deleting a character, replacing a character, and, optionally, transposing two adjacent characters.
By default, the spelling corrector dictionary contains only English words. To manage the spelling corrector dictionary, see the Spelling corrector page of the Managing dictionaries section.
MaxMistakeCount is the maximum number of mistakes possible in each word of a search query. The default value is 2. A value greater than 10 is treated as 10, and a negative value is treated as 0.
OnlyBestResults is a value indicating whether only the best results will be returned by the spelling corrector. The default value is false.
OnlyBestResultsRange is the maximum exceeding of the minimum number of mistakes that are found by the spelling corrector. The default value is 0.
ConsiderTranspositions is a value indicating whether the spelling corrector must consider transposition of two adjacent characters as a single mistake (true) or two mistakes (false). The default value is true.
Spelling correction cannot be combined with case-sensitive search. If both are enabled, the search returns an empty result and the error is reported through the ErrorOccurred event (see Search options).
Since version 26.10, spelling correction uses as many threads as there are processor cores by default. Therefore, the order of the found words in the search result may differ from run to run. To get the same order every time, set the SearchThreads index setting to NumberOfThreads.One.
The following example shows how to perform a search using the spelling correction.
C#
stringindexFolder=@"c:\MyIndex\";stringdocumentsFolder=@"c:\MyDocuments\";// Creating an index in the specified folderIndexindex=newIndex(indexFolder);// Indexing documents from the specified folderindex.Add(documentsFolder);// Creating a search options instanceSearchOptionsoptions=newSearchOptions();options.SpellingCorrector.Enabled=true;// Enabling the spelling correctionoptions.SpellingCorrector.MaxMistakeCount=1;// Setting the maximum number of mistakesoptions.SpellingCorrector.OnlyBestResults=true;// Enabling the option for only the best results of the spelling correction// Search for the word "Rleativity" containing a spelling error// The word "Relativity" will be found that differs from the search query in two transposed lettersSearchResultresult=index.Search("Rleativity",options);
More resources
GitHub examples
You may easily run the code from documentation articles and see the features in action in our GitHub examples: