The fuzzy-match Reference Manual

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.

Table of Contents


1 Introduction


2 Systems

The main system appears first, followed by any subsystem dependency.


2.1 fuzzy-match

From a string input and a list of candidates, return the most relevant candidates first.

Maintainer

vindarel <>

Author

Nyxt project, Ambrevar, Vindarel

Home Page

https://github.com/vindarel/fuzzy-match

Source Control

(GIT git@github.com:vindarel/fuzzy-match.git)

Bug Tracker

https://github.com/vindarel/fuzzy-match/issues

License

MIT

Long Description

# 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

Version

0.2

Dependencies
  • str (system).
  • mk-string-metrics (system).
Source

fuzzy-match.asd.

Child Component

fuzzy-match.lisp (file).


3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


3.1 Lisp


3.1.1 fuzzy-match/fuzzy-match.asd

Source

fuzzy-match.asd.

Parent Component

fuzzy-match (system).

ASDF Systems

fuzzy-match.


3.1.2 fuzzy-match/fuzzy-match.lisp

Source

fuzzy-match.asd.

Parent Component

fuzzy-match (system).

Packages

fuzzy-match.

Public Interface
Internals

4 Packages

Packages are listed by definition order.


4.1 fuzzy-match

Source

fuzzy-match.lisp.

Use List

common-lisp.

Public Interface
Internals

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


5.1 Public Interface


5.1.1 Special variables

Special Variable: *threshold*

The score threshold below which candidates are discarded.

Package

fuzzy-match.

Source

fuzzy-match.lisp.


5.1.2 Ordinary functions

Function: fuzzy-match (input candidates &key key threshold)

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.

Package

fuzzy-match.

Source

fuzzy-match.lisp.


5.2 Internals


5.2.1 Special variables

Special Variable: *debug*

If t, print scores.

Package

fuzzy-match.

Source

fuzzy-match.lisp.


5.2.2 Ordinary functions

Function: filter-by-threshold (items &key threshold)

Keep items (plist with :string and :score keys) only if score is >= than THRESHOLD. If THRESHOLD isn’t a number, return all items.

Package

fuzzy-match.

Source

fuzzy-match.lisp.

Function: find-exactly-matching-substrings (input candidates &key substring-length)

Return the list of input substrings that match at least one candidate. The substrings must be SUBSTRING-LENGTH characters long or more.

Package

fuzzy-match.

Source

fuzzy-match.lisp.

Function: input (plist)
Package

fuzzy-match.

Source

fuzzy-match.lisp.

Function: item (plist)
Package

fuzzy-match.

Source

fuzzy-match.lisp.

Function: keep-exact-matches-in-candidates (input pairs)

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.

Package

fuzzy-match.

Source

fuzzy-match.lisp.

Function: score (plist)
Package

fuzzy-match.

Source

fuzzy-match.lisp.

Function: score-candidate (input candidate)

Return a CANDIDATE’s score for INPUT.
A higher score means the candidate comes first.

Package

fuzzy-match.

Source

fuzzy-match.lisp.

Function: score-sort-candidates (input pairs)

Score and sort PAIRS, the pair closest to INPUT in the levenshtein distance comes first. PAIRS is a list of (search-string real-item).

Package

fuzzy-match.

Source

fuzzy-match.lisp.

Function: substring-norm (substrings string &key substring-length)

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.

Package

fuzzy-match.

Source

fuzzy-match.lisp.

Function: to-unicode (input)

Convert INPUT to (simple-array character) type.

Package

fuzzy-match.

Source

fuzzy-match.lisp.


Appendix A Indexes


A.1 Concepts