Skip to end of metadata
Go to start of metadata
Contents Summary
 

The code in below examples uses some methods defined in Common Utilities

Spelling Corrector

This feature is supported by version 17.1.0 or greater.

GroupDocs.Search for .NET API has introduced this very exciting feature allowing the correction of misspelled words in a query before performing search operation.
Spelling corrector supports 4 types of mistakes:

  • Insertion of a single character
  • Deletion of a single character
  • Substitution of a single character
  • Transposition of two adjacent characters

Spelling corrector supports up to 3 mistakes for each word in a query. The increase of error count increases the time of the search.
Spelling corrector has default collection of English words but a user can modify the collection by managing a dictionary of spellings.

Using Spelling Corrector

The Recipe

To use a spelling corrector, the following steps are needed to be followed:

  • Create or load index
  • Add documents to index
  • Initialize an object of SearchParameters() and name it parameters
  • Enable spelling corrector using "parameters.SpellingCorrector.Enabled = True"
  • Set up maximum mistake count using "parameters.SpellingCorrector.MaxMistakeCount = 1". Note that default value for maximum mistake count is 2
  • Search for some misspelled word using "index.Search(misspelled search query, parameters)"

The Code

The following code snippet shows how to use spelling corrector

Manage Dictionary of Spelling Corrector

The Recipe

To manage the dictionary of a spelling corrector, the following steps are needed to be followed:

  • Create or load index
  • Add documents to index
  • Remove all words from spelling corrector dictionary using "index.Dictionaries.SpellingCorrector.Clear()"
  • Import spelling dictionary from the file using "index.Dictionaries.SpellingCorrector.ImportDictionary(Utilities.spellingDictionaryFilePath)". Existing words are staying
  • Add word array to the dictionary using "index.Dictionaries.SpellingCorrector.AddRange(array of words)". Words are case insensitive
  • Export spelling dictionary to file using "index.Dictionaries.SpellingCorrector.ExportDictionary(Utilities.exportedSpellingDictionaryFilePath)"
  • Initialize an object of SearchParameters() and name it parameters
  • Enable spelling corrector using "parameters.SpellingCorrector.Enabled = True"
  • Set up maximum mistake count using "parameters.SpellingCorrector.MaxMistakeCount = 1". Note that default value for maximum mistake count is 2
  • Search for some misspelled word using "index.Search(misspelled search query, parameters)"

The Code

The following code snippet shows how to manage dictionary of Spelling Corrector

Only Best Results Option for Spelling Corrector

This feature is supported by version 17.8.0 or greater

GroupDocs.Search for .NET allows its users to perform spelling correction by collecting results with only minimum mistake count and discarding worse results.
Enabling this option can greatly improve the performance of spelling corrector. The Boolean property OnlyBestResults has been added to GroupDocs.Search.SpellingCorrectorParameters class to achieve this functionality.

The Recipe

To perform spelling correction with only best results options, the following steps are needed to be followed:

  • Create or load index
  • Add documents to index
  • Initialize an object of SearchParameters() and name it parameters
  • Enable spelling corrector using "parameters.SpellingCorrector.Enabled = True"
  • Set up maximum mistake count using "parameters.SpellingCorrector.MaxMistakeCount = 1". Note that default value for maximum mistake count is 2
  • Enable the only best results option using parameters.SpellingCorrector.OnlyBestResults = True
  • Search for some misspelled word using "index.Search(misspelled search query, parameters)", you will get only the best results with minimum mistake count

The Code

The below mentioned example shows how to use OnlyBestResults option in spelling corrector

Only Best Results Range Option for Spelling Corrector

This feature is supported by version 17.9.0 or greater

GroupDocs.Search for .NET allows its users to perform spelling correction by collecting the best results, as well as results with a larger number of mistakes in a
given range.
For example, suppose that the correction is performed for a maximum of 10 mistakes with a range of 2. If words with a minimum of 5 mistakes are found, then also words with 6 and 7 mistakes will be included in the final result.
The default value for the OnlyBestResultsRange property is 0. This means that by default there will only be words with a minimum number of mistakes in the results of the spelling correction. The Boolean property OnlyBestResultsRange has been added to GroupDocs.Search.SpellingCorrectorParameters class to achieve this functionality.

The Recipe

To perform spelling correction with only best results range options, the following steps are needed to be followed:

  • Create or load index
  • Add documents to index
  • Initialize an object of SearchParameters() and name it parameters
  • Enable spelling corrector using "parameters.SpellingCorrector.Enabled = True"
  • Set up maximum mistake count using "parameters.SpellingCorrector.MaxMistakeCount = 1". Note that default value for maximum mistake count is 2
  • Enable the only best results option using parameters.SpellingCorrector.OnlyBestResults = True
  • Set best results range to let's say 2 by using parameters.SpellingCorrector.OnlyBestResultsRange = 2
  • Search for some misspelled word using "index.Search(misspelled search query, parameters)", you will get only the best results within the range defined by you

The Code

The below mentioned example shows how to use OnlyBestResultsRange option in spelling corrector

Consider Transpositions Option for Spelling Corrector

This feature is supported by version 17.9.0 or greater

GroupDocs.Search for .NET allows its users to consider transposition of two adjacent characters as a single mistake when the option is enabled, or as two mistakes, when the option is disabled.The default value for the ConsiderTranspositions property is true.
The Boolean property ConsiderTranspositions has been added to GroupDocs.Search.SpellingCorrectorParameters class to achieve this functionality.

The Recipe

To perform spelling correction with considering transposition option, the following steps are needed to be followed:

  • Create or load index
  • Add documents to index
  • Initialize an object of SearchParameters() and name it parameters
  • Enable spelling corrector using "parameters.SpellingCorrector.Enabled = True"
  • Set up spelling corrector to consider transposition as a single mistake by setting ConsiderTranspositions = true or set ConsiderTranspositions = false if you don't want spelling corrector to consider transposition as a single mistake.
  • Search for some misspelled word using "index.Search(misspelled search query, parameters)"

The Code

The below mentioned example shows how to use ConsiderTranspositions option in spelling corrector

Labels
  • No labels