Spelling corrector

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 a list of words contained in the spelling corrector dictionary, the get_words method is used.

To add words to the spelling corrector dictionary, use the add_range method.

The clear method is used to remove all words from the spelling corrector dictionary.

To export words to a file, use the export_dictionary method.

To import words from a file, use the import_dictionary method. Errors of exporting and importing are reported by the error_occurred event of the index instead of exceptions.

The following example demonstrates the use of methods of the spelling corrector.

from groupdocs.search import Index

# Creating or opening an index in the specified folder
index = Index("./index")

corrector = index.dictionaries.spelling_corrector

if corrector.count > 0:
    # Removing all words from the dictionary
    corrector.clear()

# Adding words to the dictionary
words = ["achieve", "accomplish", "attain", "reach"]
corrector.add_range(words)

# Getting all words of the dictionary
all_words = corrector.get_words()
print("Words in the dictionary:", len(all_words))

# Exporting words to a file
corrector.export_dictionary("./Words.txt")

# Importing words from a file
corrector.import_dictionary("./Words.txt")
Words in the dictionary: 4

Download full output

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 the full-featured 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.