spell.suggestDetailed( dictionary_uris as String[], word as String, [options as Object?] ) as Array
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.
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.
// 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 // } ]
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.