spell:suggest-detailed( $dictionary_uris as xs:string*, $word as xs:string, [$options as (element()|map:map)?] ) as element(spell:suggestion)*
Suggests a list of spellings for a word. Returns
a sequence of elements
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 key-distance
and word-distance
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 sequence.
xquery version "1.0-ml"; spell:suggest-detailed("/my/dictionary.xml", "occasionally") (: Returns a sequence of spell:suggestion elements from the : dictionary with the URI "/my/dictionary.xml", similar to the following: <spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" xmlns:spell="http://marklogic.com/xdmp/spell"> <spell:word distance="0" key-distance="0" word-distance="0" levenshtein-distance="0">occasionally</spell:word> </spell:suggestion> <spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" xmlns:spell="http://marklogic.com/xdmp/spell"> <spell:word distance="26" key-distance="0" word-distance="90" levenshtein-distance="2">occasional</spell:word> </spell:suggestion> <spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" xmlns:spell="http://marklogic.com/xdmp/spell"> <spell:word distance="76" key-distance="1" word-distance="180" levenshtein-distance="4">occasion</spell:word> </spell:suggestion> <spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" xmlns:spell="http://marklogic.com/xdmp/spell"> <spell:word distance="76" key-distance="1" word-distance="185" levenshtein-distance="4">occasions</spell:word> </spell:suggestion> <spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" xmlns:spell="http://marklogic.com/xdmp/spell"> <spell:word distance="76" key-distance="1" word-distance="190" levenshtein-distance="4">occasion's</spell:word> </spell:suggestion> <spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" xmlns:spell="http://marklogic.com/xdmp/spell"> <spell:word distance="76" key-distance="1" word-distance="190" levenshtein-distance="4">occasioned</spell:word> </spell:suggestion> <spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" xmlns:spell="http://marklogic.com/xdmp/spell"> <spell:word distance="76" key-distance="1" word-distance="190" levenshtein-distance="4">optionally</spell:word> </spell:suggestion> <spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" xmlns:spell="http://marklogic.com/xdmp/spell"> <spell:word distance="80" key-distance="1" word-distance="200" levenshtein-distance="4">irrationally</spell:word> </spell:suggestion> :)
(: Using an options element :) xquery version "1.0-ml"; spell:suggest-detailed( "/my/dictionary.xml", "occasionally", <options xmlns="http://marklogic.com/xdmp/spell"> <distance-threshold>200</distance-threshold> <maximum>4</maximum> </options> ) (: Returns a sequence of spell:suggestion elements similar to : the following, based on the entries in the dictionary with the : URI "/my/dictionary.xml": <spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" xmlns:spell="http://marklogic.com/xdmp/spell"> <spell:word distance="0" key-distance="0" word-distance="0" levenshtein-distance="0">occasionally</spell:word> </spell:suggestion> <spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" xmlns:spell="http://marklogic.com/xdmp/spell"> <spell:word distance="26" key-distance="0" word-distance="90" levenshtein-distance="2">occasional</spell:word> </spell:suggestion> <spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" xmlns:spell="http://marklogic.com/xdmp/spell"> <spell:word distance="76" key-distance="1" word-distance="180" levenshtein-distance="4">occasion</spell:word> </spell:suggestion> <spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" xmlns:spell="http://marklogic.com/xdmp/spell"> <spell:word distance="76" key-distance="1" word-distance="185" levenshtein-distance="4">occasions</spell:word> </spell:suggestion> :)
(: Using an options map :) xquery version "1.0-ml"; spell:suggest-detailed( "/my/dictionary.xml", "occasionally", map:map() => map:with("distanceThreshold", 200) => map:with("maximum", 4) ) (: Returns a sequence of spell:suggestion elements similar to : the following, based on the entries in the dictionary with the : URI "/my/dictionary.xml": <spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" xmlns:spell="http://marklogic.com/xdmp/spell"> <spell:word distance="0" key-distance="0" word-distance="0" levenshtein-distance="0">occasionally</spell:word> </spell:suggestion> <spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" xmlns:spell="http://marklogic.com/xdmp/spell"> <spell:word distance="26" key-distance="0" word-distance="90" levenshtein-distance="2">occasional</spell:word> </spell:suggestion> <spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" xmlns:spell="http://marklogic.com/xdmp/spell"> <spell:word distance="76" key-distance="1" word-distance="180" levenshtein-distance="4">occasion</spell:word> </spell:suggestion> <spell:suggestion original="occasionally" dictionary="/my/dictionary.xml" xmlns:spell="http://marklogic.com/xdmp/spell"> <spell:word distance="76" key-distance="1" word-distance="185" levenshtein-distance="4">occasions</spell:word> </spell:suggestion> :)
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.