Skip to content

Instantly share code, notes, and snippets.

@grtjn
Created October 22, 2015 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grtjn/e7bd6f0a86631a88d0bd to your computer and use it in GitHub Desktop.
Save grtjn/e7bd6f0a86631a88d0bd to your computer and use it in GitHub Desktop.
Spell suggestions driven from lexicon
xquery version "1.0-ml";
let $term := "werld"
let $start-char := substring($term,1,1)
let $limit := 10
let $threshold := 100
return (
for $candidate in cts:field-words("meta-content",$start-char)
let $distance :=
if (starts-with($candidate, $start-char) and string-length($candidate) le 64) then
spell:levenshtein-distance($term, $candidate)
else 9999999
where $distance le $threshold
order by $distance
return concat($candidate, ' - ', $distance)
)[1 to $limit]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment