Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lithammer/fuzzysearch
:pig: Tiny and fast fuzzy search in Go
https://github.com/lithammer/fuzzysearch
algorithm fuzzy-search go
Last synced: 20 days ago
JSON representation
:pig: Tiny and fast fuzzy search in Go
- Host: GitHub
- URL: https://github.com/lithammer/fuzzysearch
- Owner: lithammer
- License: mit
- Created: 2015-07-21T10:01:44.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-10-01T04:58:33.000Z (about 1 month ago)
- Last Synced: 2024-10-09T22:17:29.170Z (26 days ago)
- Topics: algorithm, fuzzy-search, go
- Language: Go
- Homepage: https://pkg.go.dev/github.com/lithammer/fuzzysearch
- Size: 129 KB
- Stars: 1,116
- Watchers: 24
- Forks: 58
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- go-awesome - Fuzzy Search - Text fuzzy search (Open source library / Search Recommendations)
- awesome-list - fuzzysearch
- awesome-golang-repositories - fuzzysearch
- awesome - fuzzysearch - :pig: Tiny and fast fuzzy search in Go (Go)
- awesome-hacking-lists - lithammer/fuzzysearch - :pig: Tiny and fast fuzzy search in Go (Go)
README
# Fuzzy Search
Inspired by [bevacqua/fuzzysearch][1], a fuzzy matching library written in
JavaScript. But contains some extras like ranking using [Levenshtein
distance][2] 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
```go
package mainimport "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`][3]
package in the standard library:```go
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`][4] package documentation for more examples.
## License
MIT
[1]: https://github.com/bevacqua/fuzzysearch
[2]: http://en.wikipedia.org/wiki/Levenshtein_distance
[3]: https://golang.org/pkg/sort/
[4]: https://pkg.go.dev/github.com/lithammer/fuzzysearch/fuzzy