{"id":13538894,"url":"https://github.com/sahilm/fuzzy","last_synced_at":"2025-05-14T05:10:21.508Z","repository":{"id":43042192,"uuid":"107894234","full_name":"sahilm/fuzzy","owner":"sahilm","description":"Go library that provides fuzzy string matching optimized for filenames and code symbols in the style of Sublime Text, VSCode, IntelliJ IDEA et al.","archived":false,"fork":false,"pushed_at":"2024-02-28T11:29:24.000Z","size":4850,"stargazers_count":1333,"open_issues_count":4,"forks_count":62,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-04-10T23:59:49.069Z","etag":null,"topics":["fuzzy","fuzzy-search","fuzzyfinder","go","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sahilm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-22T19:03:08.000Z","updated_at":"2025-03-30T22:18:52.000Z","dependencies_parsed_at":"2022-07-22T01:48:22.191Z","dependency_job_id":"b85b2116-be38-44d2-89c5-1e087309da53","html_url":"https://github.com/sahilm/fuzzy","commit_stats":{"total_commits":44,"total_committers":8,"mean_commits":5.5,"dds":"0.20454545454545459","last_synced_commit":"c72cd382d3e5d909050f33a81c00a3c94f1efa47"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sahilm%2Ffuzzy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sahilm%2Ffuzzy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sahilm%2Ffuzzy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sahilm%2Ffuzzy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sahilm","download_url":"https://codeload.github.com/sahilm/fuzzy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254076849,"owners_count":22010611,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fuzzy","fuzzy-search","fuzzyfinder","go","golang"],"created_at":"2024-08-01T09:01:17.434Z","updated_at":"2025-05-14T05:10:21.443Z","avatar_url":"https://github.com/sahilm.png","language":"Go","funding_links":[],"categories":["开源类库","\u003ca id=\"683b645c2162a1fce5f24ac2abfa1973\"\u003e\u003c/a\u003e漏洞\u0026\u0026漏洞管理\u0026\u0026漏洞发现/挖掘\u0026\u0026漏洞开发\u0026\u0026漏洞利用\u0026\u0026Fuzzing","Go","Open source library","Repositories"],"sub_categories":["文本处理","功能","Word Processing"],"readme":"\u003cimg src=\"assets/search-gopher-1.png\" alt=\"gopher looking for stuff\"\u003e  \u003cimg src=\"assets/search-gopher-2.png\" alt=\"gopher found stuff\"\u003e\n\n# fuzzy\n[![Build Status](https://travis-ci.org/sahilm/fuzzy.svg?branch=master)](https://travis-ci.org/sahilm/fuzzy)\n[![Documentation](https://godoc.org/github.com/sahilm/fuzzy?status.svg)](https://godoc.org/github.com/sahilm/fuzzy)\n\nGo library that provides fuzzy string matching optimized for filenames and code symbols in the style of Sublime Text, \nVSCode, IntelliJ IDEA et al. This library is external dependency-free. It only depends on the Go standard library.\n\n## Features\n\n- Intuitive matching. Results are returned in descending order of match quality. Quality is determined by:\n  - The first character in the pattern matches the first character in the match string.\n  - The matched character is camel cased.\n  - The matched character follows a separator such as an underscore character.\n  - The matched character is adjacent to a previous match.\n\n- Speed. Matches are returned in milliseconds. It's perfect for interactive search boxes.\n\n- The positions of matches are returned. Allows you to highlight matching characters.\n\n- Unicode aware.\n\n## Demo\n\nHere is a [demo](_example/main.go) of matching various patterns against ~16K files from the Unreal Engine 4 codebase.\n\n![demo](assets/demo.gif)\n\nYou can run the demo yourself like so:\n\n```\ncd _example/\ngo get github.com/jroimartin/gocui\ngo run main.go\n```\n\n## Usage\n\nThe following example prints out matches with the matched chars in bold.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/sahilm/fuzzy\"\n)\n\nfunc main() {\n\tconst bold = \"\\033[1m%s\\033[0m\"\n\tpattern := \"mnr\"\n\tdata := []string{\"game.cpp\", \"moduleNameResolver.ts\", \"my name is_Ramsey\"}\n\n\tmatches := fuzzy.Find(pattern, data)\n\n\tfor _, match := range matches {\n\t\tfor i := 0; i \u003c len(match.Str); i++ {\n\t\t\tif contains(i, match.MatchedIndexes) {\n\t\t\t\tfmt.Print(fmt.Sprintf(bold, string(match.Str[i])))\n\t\t\t} else {\n\t\t\t\tfmt.Print(string(match.Str[i]))\n\t\t\t}\n\t\t}\n\t\tfmt.Println()\n\t}\n}\n\nfunc contains(needle int, haystack []int) bool {\n\tfor _, i := range haystack {\n\t\tif needle == i {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n``` \nIf the data you want to match isn't a slice of strings, you can use `FindFrom` by implementing\nthe provided `Source` interface. Here's an example:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/sahilm/fuzzy\"\n)\n\ntype employee struct {\n\tname string\n\tage  int\n}\n\ntype employees []employee\n\nfunc (e employees) String(i int) string {\n\treturn e[i].name\n}\n\nfunc (e employees) Len() int {\n\treturn len(e)\n}\n\nfunc main() {\n\temps := employees{\n\t\t{\n\t\t\tname: \"Alice\",\n\t\t\tage:  45,\n\t\t},\n\t\t{\n\t\t\tname: \"Bob\",\n\t\t\tage:  35,\n\t\t},\n\t\t{\n\t\t\tname: \"Allie\",\n\t\t\tage:  35,\n\t\t},\n\t}\n\tresults := fuzzy.FindFrom(\"al\", emps)\n\tfor _, r := range results {\n\t\tfmt.Println(emps[r.Index])\n\t}\n}\n```\n\nCheck out the [godoc](https://godoc.org/github.com/sahilm/fuzzy) for detailed documentation.\n\n## Installation\n\n`go get github.com/sahilm/fuzzy` or use your favorite dependency management tool.\n\n## Speed\n\nHere are a few benchmark results on a normal laptop.\n\n```\nBenchmarkFind/with_unreal_4_(~16K_files)-4         \t     100\t  12915315 ns/op\nBenchmarkFind/with_linux_kernel_(~60K_files)-4     \t      50\t  30885038 ns/op\n```\n\nMatching a pattern against ~60K files from the Linux kernel takes about 30ms.\n\n## Contributing\n\nEveryone is welcome to contribute. Please send me a pull request or file an issue. I promise\nto respond promptly.\n\n## Credits\n\n* [@ericpauley](https://github.com/ericpauley) \u0026 [@lunixbochs](https://github.com/lunixbochs) contributed Unicode awareness and various performance optimisations.\n\n* The algorithm is based of the awesome work of [forrestthewoods](https://github.com/forrestthewoods/lib_fts/blob/master/code/fts_fuzzy_match.js). \nSee [this](https://blog.forrestthewoods.com/reverse-engineering-sublime-text-s-fuzzy-match-4cffeed33fdb#.d05n81yjy)\nblog post for details of the algorithm.\n\n* The artwork is by my lovely wife Sanah. It's based on the Go Gopher.\n\n* The Go gopher was designed by Renee French (http://reneefrench.blogspot.com/). \nThe design is licensed under the Creative Commons 3.0 Attributions license.\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2017 Sahil Muthoo\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsahilm%2Ffuzzy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsahilm%2Ffuzzy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsahilm%2Ffuzzy/lists"}