levenshteinMatch.php
Table of Contents
Functions
- levenshteinMatch() : string
- Match documents within a (Damerau-)Levenshtein distance of a target string.
Functions
levenshteinMatch()
Match documents within a (Damerau-)Levenshtein distance of a target string.
levenshteinMatch(string $path, string $target, int $distance[, bool|null $transpositions = null ][, int|null $maxTerms = null ][, string|null $prefix = null ]) : string
Wraps the ArangoDB AQL function
LEVENSHTEIN_MATCH(path, target, distance, transpositions, maxTerms, prefix).
By default a Damerau-Levenshtein distance is computed (transpositions count
as one operation); pass transpositions: false for a pure Levenshtein distance.
The maximum distance is 4 without transpositions and 3 with them.
AQL arguments are positional: when a later option is provided, the helper
fills the earlier omitted ones with the official server defaults
(transpositions = true, maxTerms = 64) so callers never need to know them.
Trailing omitted options are not emitted at all. When using $prefix, the
prefix must be removed from $target (the distance is computed on the
remainders — see the official documentation).
Example AQL usage:
LEVENSHTEIN_MATCH(doc.text, "quikc", 2, false) // pure Levenshtein, matches "quick"
LEVENSHTEIN_MATCH(doc.text, "kc", 1, false, 64, "qui") // prefix search
Parameters
- $path : string
-
Attribute path expression to test (kept raw).
- $target : string
-
String to compare against (emitted as a quoted string literal).
- $distance : int
-
Maximum edit distance:
0…4if$transpositionsisfalse,0…3otherwise. - $transpositions : bool|null = null
-
Optional —
falsefor a pure Levenshtein distance (server defaulttrue). - $maxTerms : int|null = null
-
Optional — number of most relevant terms to consider,
0for all (server default64). - $prefix : string|null = null
-
Optional — known common prefix (emitted as a quoted string literal); improves performance.
Tags
Return values
string —The formatted AQL expression.