MarkLogic Server 11.0 Product Documentation
spell.suggestDetailed

spell.suggestDetailed(
   dictionary_uris as String[],
   word as String,
   [options as Object?]
) as Array

Summary

Suggests a list of spellings for a word. Returns an array of objects describing each suggestion, including the suggested word, the distance, the key distance, the word distance, and the levenshtein distance. You can use this extra information to make your own decisions about which suggestions to use. If you do not want to use this information, use the spell.suggest function instead.

Parameters
dictionary_uris The URIs of the dictionaries to use.
word The word for which you get spelling suggestions.
options Options with which to customize this operation. This function supports the following options:
maximum
Specifies the maximum number of suggestions to be returned. The default is 10.
distanceThreshold
Specifies a cut off threshold for suggestions having a distance less than the given number. The distance is a weighted number indicating the "distance" between two words, where lower numbers indicate a closer match. The default is 100, which means that distances less than or equal to 100 are considered as suggestions.

Usage Notes

This function is built-in, so you do not need to import a library module to use it.

This function only provides suggestions to words that are less than 256 characters in length; words 256 characters or longer return no suggestions. Also, it removes any dictionary entries that are 256 characters or more, so it will never return a suggestion with greater than 256 characters.

The keyDistance and wordDistance values in the output are used by the double metaphone algorithm to calculate the distance, which is a weighted number indicating how close a word is to the one in the dictionary.

If there are no suggestions, this function returns an empty array.

Example

// Assume you create a dictionary as follows, with the URI "two-words.json":

declareUpdate();
const spell = require('/MarkLogic/spell');
spell.insert('two-words.json', {words: ['albatross','albatrosses']});

// ---------------------------------------------------------
// After installation, use the dictionary to generate suggestions as
// follows:

spell.suggestDetailed(
  'two-words.json', 'albetros',
  { maximum: 5, distanceThreshold: 500 }
);

// Returns an array of suggestion objects of the following form:
//
// [ { "original": "albetros", 
//     "word": "albatross", 
//     "dictionary": "two-words.json", 
//     "distance": 26, 
//     "keyDistance": 0, 
//     "wordDistance": 95, 
//     "levenshteinDistance": 2
//   },{
//     "original": "albetros", 
//     "word": "albatrosses", 
//     "dictionary": "two-words.json", 
//     "distance": 76, 
//     "keyDistance": 1, 
//     "wordDistance": 185, 
//     "levenshteinDistance": 4
//  } ]
Powered by MarkLogic Server | Terms of Use | Privacy Policy