{"id":36534944,"url":"https://github.com/raphamorim/fuzzy","last_synced_at":"2026-01-15T02:46:14.841Z","repository":{"id":332009407,"uuid":"1026841496","full_name":"raphamorim/fuzzy","owner":"raphamorim","description":"fuzzy matching with Levenshtein, Damerau-Levenshtein, Bitap and n-gram","archived":false,"fork":false,"pushed_at":"2025-07-31T13:50:51.000Z","size":3392,"stargazers_count":21,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-12T05:50:52.115Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/raphamorim.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-26T18:16:14.000Z","updated_at":"2025-12-03T02:11:36.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/raphamorim/fuzzy","commit_stats":null,"previous_names":["raphamorim/fuzzy"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/raphamorim/fuzzy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raphamorim%2Ffuzzy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raphamorim%2Ffuzzy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raphamorim%2Ffuzzy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raphamorim%2Ffuzzy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/raphamorim","download_url":"https://codeload.github.com/raphamorim/fuzzy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raphamorim%2Ffuzzy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28441487,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-15T00:55:22.719Z","status":"online","status_checked_at":"2026-01-15T02:00:08.019Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2026-01-12T03:11:19.849Z","updated_at":"2026-01-15T02:46:14.834Z","avatar_url":"https://github.com/raphamorim.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fuzzy\n\nA comprehensive fuzzy search library implementing state-of-the-art algorithms and data structures for approximate string matching, text search, and similarity detection.\n\n## Features\n\n### Distance Metrics\n- **Levenshtein Distance**: Classic edit distance algorithm\n- **Damerau-Levenshtein Distance**: Supports transpositions\n- **Myers' Algorithm**: Efficient diff algorithm for edit distance\n\n### Data Structures\n- **BK-Tree**: Metric tree for efficient similarity search\n- **Suffix Array**: For substring search and pattern matching\n- **FM-Index**: Compressed full-text index based on Burrows-Wheeler Transform\n\n### Indexing Methods\n- **N-gram Indexing**: Character n-gram based search with Jaccard similarity\n- **Trigram Index**: Optimized 3-gram indexing for approximate matching\n- **Q-gram Distance**: Distance metric based on q-gram profiles\n\n### Locality-Sensitive Hashing\n- **MinHash LSH**: For finding similar documents\n- **SimHash**: Near-duplicate detection using hamming distance\n\n### Advanced Algorithms\n- **Wu-Manber**: Bit-parallel approximate string matching\n- **Ukkonen A***: A* search for approximate pattern matching\n- **Bitonic Sort**: Parallel-friendly sorting for fuzzy matches\n\n![Benchmark](benchmark/plot/scaling_performance.png)\n\n## Installation\n\n```bash\ngo get github.com/raphamorim/fuzzy\n```\n\n## Usage Examples\n\n### BK-Tree for Spell Checking\n\n```go\ntree := fuzzy.NewBKTree()\nwords := []string{\"book\", \"books\", \"cake\", \"boo\", \"boon\", \"cook\"}\nfor _, word := range words {\n    tree.Add(word)\n}\n\n// Find words within edit distance 2 of \"bok\"\nsuggestions := tree.Search(\"bok\", 2)\n// Returns: [\"book\", \"boo\", \"cook\"]\n```\n\n### N-gram Search\n\n```go\nng := fuzzy.NewNGram(3)\nng.Add(\"hello world\", 0)\nng.Add(\"hello there\", 1)\nng.Add(\"goodbye world\", 2)\n\n// Search with similarity threshold\nresults := ng.Search(\"helo wrld\", 0.3)\n// Returns indices of matching documents\n```\n\n### LSH for Document Similarity\n\n```go\nlsh := fuzzy.NewLSH(10, 5, 3) // 10 hash tables, 5 hash functions, 3-shingles\nlsh.Add(\"The quick brown fox jumps over the lazy dog\")\nlsh.Add(\"The fast brown fox jumps over the lazy cat\")\n\nsimilar := lsh.Query(\"The quick brown fox leaps over the lazy dog\", 0.7)\n// Returns indices of similar documents\n```\n\n### Wu-Manber Approximate Search\n\n```go\nwm := fuzzy.NewWuManber(\"pattern\")\ntext := \"This text contains a patern with an error\"\nmatches := wm.Search(text, 1) // Allow 1 error\n\nfor _, match := range matches {\n    fmt.Printf(\"Found at position %d-%d with %d errors\\n\", \n        match.Start, match.End, match.Distance)\n}\n```\n\n## Benchmarks\n\nRun benchmarks with:\n```bash\ngo test -bench=. ./...\n```\n\n## Algorithm Comparison\n\n### Key Differences\n\n| Algorithm | Type | Best Use Case | Strengths | Limitations |\n|-----------|------|---------------|-----------|-------------|\n| **BK-Tree** | Tree-based | Spell checking, typo correction | Exact edit distance, efficient for small distances | Slower for large edit distances |\n| **LSH** | Hash-based | Near-duplicate detection, document similarity | Very fast queries, probabilistic | Approximate results, needs tuning |\n| **Suffix Array** | Index-based | Substring search, pattern matching | Exact matches, handles large texts | High memory usage, slow updates |\n| **Wu-Manber** | Bit-parallel | Pattern search with errors | Fast streaming search, configurable errors | Limited pattern length |\n| **N-gram** | Statistical | Partial matching, similarity scoring | Flexible similarity metrics, language-agnostic | Less precise than edit distance |\n\n### Algorithm Complexity\n\n| Algorithm | Build Time | Search Time | Space |\n|-----------|------------|-------------|-------|\n| BK-Tree | O(n log n) | O(log n) | O(n) |\n| Suffix Array | O(n log n) | O(log n + m) | O(n) |\n| FM-Index | O(n log n) | O(m) | O(n) |\n| N-gram Index | O(n) | O(m + k) | O(n) |\n| LSH | O(n) | O(1) | O(n) |\n| Wu-Manber | O(m) | O(n) | O(m) |\n\nWhere:\n- n = text/corpus size\n- m = pattern size\n- k = number of results\n\n## Comparison with Other Libraries\n\n- **sahilm/fuzzy**: Uses a simple character-by-character matching algorithm optimized for editor-style filename matching\n- **lithammer/fuzzysearch**: Implements basic fuzzy matching with Levenshtein distance ranking\n\nThis library implements advanced algorithms not found in those libraries:\n- BK-trees and other metric tree structures\n- Suffix arrays and FM-indexes for large text search\n- N-gram based indexing\n- Locality-sensitive hashing approaches\n- Advanced edit distance algorithms like Myers' algorithm and Wu-Manber\n\n## License\n\nGPL-3.0","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraphamorim%2Ffuzzy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraphamorim%2Ffuzzy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraphamorim%2Ffuzzy/lists"}