fuzzymatch

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2025 License: MIT Imports: 1 Imported by: 0

README

fuzzymatch

A simple Go package for fuzzy string matching using the Levenshtein distance algorithm. Find the closest match to a string from a list of possibilities, perfect for handling typos or approximate searches.

Installation

To use fuzzymatch in your Go project, run:

go get github.com/CodeIntelligenceTesting/fuzzymatch

Usage

Here's a quick example of how to use fuzzymatch:

package main

import (
	"fmt"
	"github.com/CodeIntelligenceTesting/fuzzymatch"
)

func main() {
	possibleMatches := []string{"foo", "bar", "baz", "foobar"}
	input := "fo"
	closest := fuzzymatch.SuggestClosestMatch(input, possibleMatches, 9999)
	if closest != "" {
		fmt.Printf("Did you mean %q?\n", closest) // Output: Did you mean "foo"?
	} else {
		fmt.Println("No close match found or exact match detected.")
	}
}

Key Functions

  • SuggestClosestMatch(s string, possibleMatches []string, minDist int) string: Returns the closest match from possibleMatches to s if within a Levenshtein distance of 3, or an empty string if no close match is found or s is an exact match.
  • Levenshtein(a, b string) int: Computes the Levenshtein distance between two strings.

Features

  • Lightweight and dependency-free.
  • Handles exact matches, close matches (up to 3 edits), and no-match cases.
  • Ideal for configuration key validation, search suggestions, or typo correction.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Levenshtein

func Levenshtein(a, b string) int

Levenshtein distance calculates the number of edits between two strings

func SuggestClosestMatch

func SuggestClosestMatch(s string, possibleMatches []string, minDist int) string

SuggestClosestMatch finds the closest string match using Levenshtein distance

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL