Loading TOC...


   $str1 as String,
   $str2 as String
) as Number


Given two strings, returns the Levenshtein distance between those strings. The Levenshtein distance is a measure of how many operations it takes to transform a string into another string, and it is useful in determining if a word is spelled correctly, or in simply comparing how "different" two words are.

$str1 The first input string.
$str2 The second input string.

Usage Notes

The spell:levenshtein-distance function is a built-in function and does not require the import module statement in the XQuery prolog.

The spell:levenshtein-distance function throws an exception if one of the strings is 256 or more characters in length and the other is at least 1 character in length.


=> 1


spell.levenshteinDistance('cat', 'cats');
=> 1

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.