This is the fuzzy-match Reference Manual, version 0.2, generated automatically by Declt version 4.0 beta 2 "William Riker" on Fri May 15 12:19:45 2026 GMT+0.
The main system appears first, followed by any subsystem dependency.
fuzzy-matchFrom a string input and a list of candidates, return the most relevant candidates first.
vindarel <vindarel@mailz.org>
Nyxt project, Ambrevar, Vindarel
(GIT git@github.com:vindarel/fuzzy-match.git)
MIT
# Fuzzy-match
Fuzzy match candidates from an input string.
On Quicklisp and [Ultralisp](https://ultralisp.org/).
~~~lisp
CL-USER> (fuzzy-match "hl" ’("foo" "bar" "hello" "hey!"))
("hello" "hey!" "foo" "bar")
~~~
~~~lisp
CL-USER> (fuzzy-match "zp" ’("foo" "zepellin" "bar: zep"))
("zepellin" "bar: zep" "foo")
~~~
To give a list of non-string candidates, use the ‘:key‘ argument, a
function that will be ‘funcall‘-ed on each candidate to get its string
representation.
“‘lisp
(defstruct candidate
(string)
(stuff))
(defparameter *objects*
(list (make-candidate :string "project-switch")
(make-candidate :string "bananas")))
(fuzzy-match "proj ws" *objects* :key #’candidate-string)
“‘
The parameters are hand-picked for the results to feel natural. A
candidate that starts with the input substring should appear
first. For example, we use the Damerau-Levenshtein distance thanks to
the ‘MK-STRING-METRICS‘ library under the hood, but we don’t obey to
its result.
# CHANGELOG
- 0.2 <2025-08-08>:
- use a ‘:key‘ parameter to work with compound objects instead of ‘:suggestions-display‘.
- use a score threshold
- regression: with no adaptative threshold so far, a short input string might not get results. E.g. searching for "bf" might not return "buffer-switch".
- or in ‘(fuzzy-match "[" ’("http://[1:0:0:2::3:0.]/" "foo") :threshold 0.01)‘ we need a low threshold.
- 0.1: initial
# Nyxt origin
This code was extracted from the Nyxt browser. Original authors: Ambrevar, Vindarel.
## Other projects using this
We know of:
- [cl-autocorrect](https://github.com/moneylobster/cl-autocorrect)
- Lem editor (soon©)
# Licence
MIT
0.2
str (system).
mk-string-metrics (system).
fuzzy-match.lisp (file).
Files are sorted by type and then listed depth-first from the systems components trees.
fuzzy-match/fuzzy-match.lispfuzzy-match (system).
*threshold* (special variable).
fuzzy-match (function).
*debug* (special variable).
filter-by-threshold (function).
find-exactly-matching-substrings (function).
input (function).
item (function).
keep-exact-matches-in-candidates (function).
score (function).
score-candidate (function).
score-sort-candidates (function).
substring-norm (function).
to-unicode (function).
Packages are listed by definition order.
fuzzy-matchcommon-lisp.
*threshold* (special variable).
fuzzy-match (function).
*debug* (special variable).
filter-by-threshold (function).
find-exactly-matching-substrings (function).
input (function).
item (function).
keep-exact-matches-in-candidates (function).
score (function).
score-candidate (function).
score-sort-candidates (function).
substring-norm (function).
to-unicode (function).
Definitions are sorted by export status, category, package, and then by lexicographic order.
The score threshold below which candidates are discarded.
From the user input and a list of candidates, return a filtered list of
candidates that have all the input words in them, and sort this list to have the
’most relevant’ first.
KEY is a function to get the candidates’ string representation. It will be funcall’ed.
THRESHOLD, a float between 0 and 1, is the minimal score for a matching result. If a match scores below it, it is discarded.
The match is case-sensitive if INPUT contains at least one uppercase character.
Keep items (plist with :string and :score keys) only if score is >= than THRESHOLD. If THRESHOLD isn’t a number, return all items.
Return the list of input substrings that match at least one candidate. The substrings must be SUBSTRING-LENGTH characters long or more.
Filter out non-exact matches from candidates.
If any input substring (split by whitespace) matches exactly (but not necessarily a whole word),
then all candidates that are not exactly matched by at least one substring are removed.
Return a CANDIDATE’s score for INPUT.
A higher score means the candidate comes first.
Score and sort PAIRS, the pair closest to INPUT in the levenshtein distance comes first. PAIRS is a list of (search-string real-item).
Return the norm of SUBSTRINGS with regard to STRING.
The norm is closer to 1 if
- substrings start near the beginning of STRING;
- substrings length are closer to the length of STRING.
Only substrings of SUBSTRING-LENGTH characters or more are considered.
Convert INPUT to (simple-array character) type.
| Jump to: | F I K S T |
|---|
| Jump to: | F I K S T |
|---|
| Jump to: | *
S |
|---|
| Jump to: | *
S |
|---|
| Jump to: | F P S |
|---|
| Jump to: | F P S |
|---|