Spell checking

During the search, a search query can be checked for spelling errors in words. To enable spelling correction in search queries, the setEnabled method of the spelling corrector options is called with the true value as an argument. 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.

The spelling corrector options class contains the following options:

  • setMaxMistakeCount sets the maximum number of mistakes possible in each word of a search query. The default value is 2.
  • setOnlyBestResults sets a value indicating whether only the best results will be returned by the spelling corrector. The default value is false.
  • setOnlyBestResultsRange sets the maximum exceeding of the minimum number of mistakes that are found by the spelling corrector. The default value is 0.
  • setConsiderTranspositions sets 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.

The following example shows how to perform a search using the spelling correction.

const indexFolder = 'c:/MyIndex/';
const documentsFolder = 'c:/MyDocuments/';

// Creating an index in the specified folder
const index = new groupdocs.search.Index(indexFolder);

// Indexing documents from the specified folder
index.add(documentsFolder);

// Creating a search options instance
const options = new groupdocs.search.SearchOptions();
options.getSpellingCorrector().setEnabled(true); // Enabling the spelling correction
options.getSpellingCorrector().setMaxMistakeCount(1); // Setting the maximum number of mistakes
options.getSpellingCorrector().setOnlyBestResults(true); // Enabling the option for only the best results of the spelling correction

// Search for the word "houseohld" containing a spelling error
// The word "household" will be found that differs from the search query in two transposed letters
const query = 'houseohld';
const result = index.search(query, options);

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.