vladivolo / fuzzysearch

:pig: Tiny and fast fuzzy search in Go

Home Page:https://godoc.org/github.com/lithammer/fuzzysearch/fuzzy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fuzzy Search

Build Status Godoc

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

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.

Usage

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.RankMatch("kitten", "sitting") // 3

words := []string{"cartwheel", "foobar", "wheel", "baz"}
fuzzy.Find("whl", words) // [cartwheel wheel]

fuzzy.RankFind("whl", words) // [{whl cartwheel 6 0} {whl wheel 2 2}]

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}]

License

MIT

About

:pig: Tiny and fast fuzzy search in Go

https://godoc.org/github.com/lithammer/fuzzysearch/fuzzy

License:MIT License


Languages

Language:Go 99.2%Language:Makefile 0.8%