{"id":2056,"url":"https://github.com/krisk/fuse-swift","last_synced_at":"2025-08-02T23:31:17.221Z","repository":{"id":20499717,"uuid":"90086637","full_name":"krisk/fuse-swift","owner":"krisk","description":"A lightweight fuzzy-search library, with zero dependencies","archived":true,"fork":false,"pushed_at":"2022-03-09T14:59:05.000Z","size":120,"stargazers_count":935,"open_issues_count":24,"forks_count":112,"subscribers_count":17,"default_branch":"master","last_synced_at":"2024-11-29T17:44:05.701Z","etag":null,"topics":["bitap","fuzzy-matching","fuzzy-search","weighted-search"],"latest_commit_sha":null,"homepage":null,"language":"Swift","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/krisk.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"krisk","patreon":"fusejs","custom":"https://www.paypal.com/paypalme2/kirorisk"}},"created_at":"2017-05-02T23:14:25.000Z","updated_at":"2024-11-29T10:35:06.000Z","dependencies_parsed_at":"2022-07-07T14:31:56.572Z","dependency_job_id":null,"html_url":"https://github.com/krisk/fuse-swift","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krisk%2Ffuse-swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krisk%2Ffuse-swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krisk%2Ffuse-swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krisk%2Ffuse-swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krisk","download_url":"https://codeload.github.com/krisk/fuse-swift/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228503084,"owners_count":17930507,"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":["bitap","fuzzy-matching","fuzzy-search","weighted-search"],"created_at":"2024-01-05T20:16:02.363Z","updated_at":"2024-12-06T17:30:30.296Z","avatar_url":"https://github.com/krisk.png","language":"Swift","funding_links":["https://github.com/sponsors/krisk","https://patreon.com/fusejs","https://www.paypal.com/paypalme2/kirorisk","https://www.paypal.me/kirorisk","https://www.patreon.com/fusejs"],"categories":["Text","Tech Stack"],"sub_categories":["Other free courses","Other Testing","Keychain"],"readme":"# Fuse\n\n[![CI Status](http://img.shields.io/travis/krisk/fuse-swift.svg?style=flat)](https://travis-ci.org/krisk/fuse-swift)\n[![Version](https://img.shields.io/cocoapods/v/Fuse.svg?style=flat)](http://cocoapods.org/pods/Fuse)\n[![License](https://img.shields.io/cocoapods/l/Fuse.svg?style=flat)](http://cocoapods.org/pods/Fuse)\n[![Platform](https://img.shields.io/cocoapods/p/Fuse.svg?style=flat)](http://cocoapods.org/pods/Fuse)\n[![Donate](https://img.shields.io/badge/Donate-PayPal-red.svg)](https://www.paypal.me/kirorisk)\n[![Donate](https://img.shields.io/badge/patreon-donate-red.svg)](https://www.patreon.com/fusejs)\n\n## What is Fuse?\n\nFuse is a super lightweight library which provides a simple way to do fuzzy searching.\n\n![Demo](https://i.postimg.cc/MZNZPD1F/bitap-search-demo.gif)\n\n## Usage\n\n#### Example 1\n\n```swift\nlet fuse = Fuse()\nlet result = fuse.search(\"od mn war\", in: \"Old Man's War\")\n\nprint(result?.score)  // 0.44444444444444442\nprint(result?.ranges) // [CountableClosedRange(0...0), CountableClosedRange(2...6), CountableClosedRange(9...12)]\n```\n\n#### Example 2\n\nSearch for a text pattern in an array of srings.\n\n```swift\nlet books = [\"The Silmarillion\", \"The Lock Artist\", \"The Lost Symbol\"]\nlet fuse = Fuse()\n\n// Improve performance by creating the pattern once\nlet pattern = fuse.createPattern(from: \"Te silm\")\n\n// Search for the pattern in every book\nbooks.forEach {\n    let result = fuse.search(pattern, in: $0)\n    print(result?.score)\n    print(result?.ranges)\n}\n```\n\n#### Example 3\n\n```swift\nclass Book: Fuseable {\n    dynamic var name: String\n    dynamic var author: String\n\n    var properties: [FuseProperty] {\n        return [\n            FuseProperty(name: \"title\", weight: 0.3),\n            FuseProperty(name: \"author\", weight: 0.7),\n        ]\n    }\n}\n\nlet books: [Book] = [\n    Book(author: \"John X\", title: \"Old Man's War fiction\"),\n    Book(author: \"P.D. Mans\", title: \"Right Ho Jeeves\")\n]\n\nlet fuse = Fuse()\nlet results = fuse.search(\"man\", in: books)\n\nresults.forEach { item in\n    print(\"index: \" + item.index)\n    print(\"score: \" + item.score)\n    print(\"results: \" + item.results)\n    print(\"---------------\")\n}\n\n// Output:\n//\n// index: 1\n// score: 0.015\n// results: [(key: \"author\", score: 0.015000000000000003, ranges: [CountableClosedRange(5...7)])]\n// ---------------\n// index: 0\n// score: 0.028\n// results: [(key: \"title\", score: 0.027999999999999997, ranges: [CountableClosedRange(4...6)])]\n```\n\n#### Example 4\n\n```swift\nlet fuse = Fuse()\nfuse.search(\"Man\", in: books, completion: { results in\n    print(results)\n})\n```\n\n### Options\n\n`Fuse` takes the following options:\n\n- `location`: Approximately where in the text is the pattern expected to be found. Defaults to `0`\n- `distance`: Determines how close the match must be to the fuzzy `location` (specified above). An exact letter match which is `distance` characters away from the fuzzy location would score as a complete mismatch. A distance of `0` requires the match be at the exact `location` specified, a `distance` of `1000` would require a perfect match to be within `800` characters of the fuzzy location to be found using a 0.8 threshold. Defaults to `100`\n- `threshold`: At what point does the match algorithm give up. A threshold of `0.0` requires a perfect match (of both letters and location), a threshold of `1.0` would match anything. Defaults to `0.6`\n- `maxPatternLength`: The maximum valid pattern length. The longer the pattern, the more intensive the search operation will be. If the pattern exceeds the `maxPatternLength`, the `search` operation will return `nil`. Why is this important? [Read this](https://en.wikipedia.org/wiki/Word_(computer_architecture)#Word_size_choice). Defaults to `32`\n- `isCaseSensitive`: Indicates whether comparisons should be case sensitive. Defaults to `false`\n\n## Example Project\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\n## Requirements\n\n## Installation\n\nFuse is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod \"Fuse\"\n```\n\n## License\n\nFuse is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrisk%2Ffuse-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrisk%2Ffuse-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrisk%2Ffuse-swift/lists"}