• Stars
    star
    979
  • Rank 45,039 (Top 1.0 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 9 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🐷 Tiny and fast fuzzy search in Go

Fuzzy Search

Inspired by bevacqua/fuzzysearch, a fuzzy matching library written in JavaScript. But contains some extras like ranking using Levenshtein distance and finding matches in a list of words.

Fuzzy searching allows for flexibly matching a string with partial input, useful for filtering data very quickly based on lightweight user input.

The current implementation uses the algorithm suggested by Mr. Aleph, a russian compiler engineer working at V8.

Install

go get github.com/lithammer/fuzzysearch/fuzzy

Usage

package main

import "github.com/lithammer/fuzzysearch/fuzzy"

func main() {
	fuzzy.Match("twl", "cartwheel")  // true
	fuzzy.Match("cart", "cartwheel") // true
	fuzzy.Match("cw", "cartwheel")   // true
	fuzzy.Match("ee", "cartwheel")   // true
	fuzzy.Match("art", "cartwheel")  // true
	fuzzy.Match("eeel", "cartwheel") // false
	fuzzy.Match("dog", "cartwheel")  // false
	fuzzy.Match("kitten", "sitting") // false
	
	fuzzy.RankMatch("kitten", "sitting") // -1
	fuzzy.RankMatch("cart", "cartwheel") // 5
	
	words := []string{"cartwheel", "foobar", "wheel", "baz"}
	fuzzy.Find("whl", words) // [cartwheel wheel]
	
	fuzzy.RankFind("whl", words) // [{whl cartwheel 6 0} {whl wheel 2 2}]
	
	// Unicode normalized matching.
	fuzzy.MatchNormalized("cartwheel", "cartwhéél") // true

	// Case insensitive matching.
	fuzzy.MatchFold("ArTeeL", "cartwheel") // true
}

You can sort the result of a fuzzy.RankFind() call using the sort package in the standard library:

matches := fuzzy.RankFind("whl", words) // [{whl cartwheel 6 0} {whl wheel 2 2}]
sort.Sort(matches) // [{whl wheel 2 2} {whl cartwheel 6 0}]

See the fuzzy package documentation for more examples.

License

MIT

More Repositories

1

shortuuid

🍄 A generator library for concise, unambiguous and URL-safe UUIDs
Go
1,084
star
2

go-wiki

A simple HTTP server rendering Markdown styled documents
Go
300
star
3

go-jump-consistent-hash

⚡ Fast, minimal memory, consistent hash algorithm
Go
214
star
4

NeavUI

Development branch of Neav UI
Lua
96
star
5

dedent

Remove any common leading whitespace from multiline strings
Go
89
star
6

python-jump-consistent-hash

Fast, minimal memory, consistent hash algorithm
Python
37
star
7

passbook_flask_example

An example Implementation of a Passbook Webservice in Flask, based on mattt's passbook_rails_example
Python
19
star
8

homebrew-deadsnakes

Homebrew tap with old and new Python versions for macOS
Ruby
12
star
9

nvim-diagnosticls

diagnostic-languageserver configuration for Neovim's language server client
Lua
10
star
10

vim-eighties

A simplified and optimized base16-eighties color scheme for Vim
Vim Script
10
star
11

webassets-browserify

Browserify filter for webassets
Python
5
star
12

dotfiles

config files etc.
Shell
4
star
13

prInformation

A lightweight WoW addon for showing various information (fps, gold, friends online etc.)
Lua
2
star
14

advent_of_code_2022

Advent of Code 2022
Rust
2
star
15

imdb-api

Very basic IMDb scraper written for Flask and Heroku
HTML
1
star
16

nvim-pylance

Add Pylance support to nvim-lspconfig
Lua
1
star
17

prButler

Making your life simpler in World of Warcraft
Lua
1
star
18

nSpellTracker

Simple buff, debuff and cooldown tracking based on rFilter3 by Zork
Lua
1
star
19

nFilger

Buff, debuff and cooldown tracker for Neav UI, based on Filger by Nils Ruesch
Lua
1
star
20

prExecute

Plays a notification sound ("Quad damage!" from Quake) when entering execution range for all classes/specs, also plays a tick sound for Drain Soul
Lua
1
star
21

webassets

A webservice to compile and compress various web assets
JavaScript
1
star