Loading TOC...

MarkLogic 12 EA 2 Product Documentation
spell:levenshtein-distance

spell:levenshtein-distance(
   $str1 as xs:string,
   $str2 as xs:string
) as xs:integer

Summary

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.

Parameters
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.

Example

spell:levenshtein-distance("albatros","albetros")
  
=> 1

Example

spell:levenshtein-distance("cat", "cats")
  
=> 1

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