Swiftpack.co - truizlop/FuzzyFind as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by truizlop.
truizlop/FuzzyFind 0.1.0
A Swift package to perform fuzzy search queries on strings
⭐️ 125
🕓 2 years ago
.package(url: "https://github.com/truizlop/FuzzyFind.git", from: "0.1.0")


A Swift package with utilities to perform fuzzy search, using a modified version of the Smith-Waterman algorithm. This implementation is a port from the Haskell version implemented by Rúnar Bjarnason.


This package includes two core functions: bestMatch and fuzzyFind.

With bestMatch, you can find the best alignment of your query into a single string, if any alignment is possible:

import FuzzyFind 

let alignment = bestMatch(query: "ff", input: "FuzzyFind") // Matches
let noAlignment = bestMatch(query: "ww", input: "FuzzyFind") // Not possible to find a match, returns nil

With fuzzyFind, you can run multiple queries over multiple inputs, and get all alignments for inputs that match all provided queries. Alignments will be provided in an array and sorted by their score; a higher score means a better alignment.

import FuzzyFind

let allAlignments = fuzzyFind(queries: ["dad", "mac", "dam"], inputs: ["red macadamia", "Madam Card"])

You can visualize the matched alignment by calling highlight() on an alignment:

let alignment = bestMatch(query: "ff", input: "FuzzyFind")!

This will print:

*    *   


Stars: 125
Last commit: 5 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Initial release
2 years ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics