{"id":16065681,"url":"https://github.com/viktorasl/fuzzysearch","last_synced_at":"2025-07-08T05:12:48.581Z","repository":{"id":56911784,"uuid":"65021975","full_name":"viktorasl/FuzzySearch","owner":"viktorasl","description":"Lightweight Fuzzy evaluation protocol with CollectionType extension","archived":false,"fork":false,"pushed_at":"2017-06-04T16:31:43.000Z","size":61,"stargazers_count":5,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-12T10:46:26.202Z","etag":null,"topics":["filter","fuzzy-search","search","swift"],"latest_commit_sha":null,"homepage":"","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/viktorasl.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}},"created_at":"2016-08-05T13:48:09.000Z","updated_at":"2025-01-30T16:06:03.000Z","dependencies_parsed_at":"2022-08-20T19:40:07.377Z","dependency_job_id":null,"html_url":"https://github.com/viktorasl/FuzzySearch","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viktorasl%2FFuzzySearch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viktorasl%2FFuzzySearch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viktorasl%2FFuzzySearch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viktorasl%2FFuzzySearch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/viktorasl","download_url":"https://codeload.github.com/viktorasl/FuzzySearch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243903159,"owners_count":20366432,"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":["filter","fuzzy-search","search","swift"],"created_at":"2024-10-09T05:13:45.875Z","updated_at":"2025-03-18T05:31:00.863Z","avatar_url":"https://github.com/viktorasl.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FuzzySearch\n\n[![Build Status](https://travis-ci.org/viktorasl/FuzzySearch.svg)](https://travis-ci.org/viktorasl/FuzzySearch)\n[![Swift Package Manager Compatible](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-4BC51D.svg?style=flat)](https://github.com/apple/swift-package-manager)\n[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/SwiftHEXColors.svg)](https://img.shields.io/cocoapods/v/FuzzySearch.svg)\n[![Platform](https://img.shields.io/cocoapods/p/SwiftHEXColors.svg?style=flat)](http://cocoadocs.org/docsets/FuzzySearch)\n[![License](https://img.shields.io/cocoapods/l/SwiftHEXColors.svg)](https://raw.githubusercontent.com/viktorasl/FuzzySearch/master/LICENSE)\n\nLightweight Fuzzy evaluation protocol with CollectionType extension\n\n## Requirements\n\niOS 8.0+\nSwift 3.0\n\n## Usage\n\n### Implementing FuzzySearchable protocol\n\n```swift\nstruct PlayerModel {\n  let name: String\n  let position: String\n  let goals: Int\n}\n```\n\nImplementation of `FuzzySearchable` protocol defines against what search patterns will be evaluated.\n```swift\nextension PlayerModel: FuzzySearchable {\n  var fuzzyStringToMatch: String {\n    return name\n  }\n}\n```\n\n### Evaluating single `FuzzySearchable` instance\n\n```swift\nlet maradona = PlayerModel(name: \"Diego Maradona\", position: \"F\", goals: 16)\nmaradona.fuzzyMatch(\"diema\") // FuzzySearchResult(weight: 15, parts: [(0,3), (6,2)])\n```\n\n#### `FuzzySearchResult`\n\nResult of evaluation carries two properties:\n- `weight` - weight of the match\n- `parts` - `NSRange`'s of pattern matching against `fuzzyStringToMatch`\n\n### Evaluating collection of `FuzzySearchable`s\n\nWhen evaluating collection of `FuzzySearchable`s result is an array of tuples `(item: Generator.Element, result: FuzzySearchResult)` which is filtered and sorted depending on `weight`.\n\n```swift\n\nlet players = [\n  PlayerModel(name: \"Diego Maradona\", position: \"CF\", goals: 16),\n  PlayerModel(name: \"David Beckham\", position: \"CAM\", goals: 8),\n  PlayerModel(name: \"Lionel Messi\", position: \"RW\", goals: 15)\n]\nplayers.fuzzyMatch(\"di\")\n//[\n// (\n//  FuzzySearchTests.PlayerModel(name: \"Diego Maradona\", position: \"CF\", goals: 16),\n//  FuzzySearch.FuzzySearchResult(weight: 4, parts: [(0,2)])\n// ), (\n//  FuzzySearchTests.PlayerModel(name: \"David Beckham\", position: \"CAM\", goals: 8),\n//  FuzzySearch.FuzzySearchResult(weight: 2, parts: [(0,1), (3,1)])\n// )\n//]\n```\n\n### `CachedFuzzySearchable\u003cT: FuzzySearchable\u003e`\n\nWraps over a `FuzzySearchable` instance, caching some underlying metadata generated while fuzzy-matching w/ `FuzzySearchable.fuzzyMatch`.\n\nUse this cached wrapper over `FuzzySearchable` instances that are expected to be fuzzy-matched multiple times without mutation to `fuzzyStringToMatch`:\n\n```swift\nlet players = [\n  PlayerModel(name: \"Diego Maradona\", position: \"CF\", goals: 16),\n  PlayerModel(name: \"David Beckham\", position: \"CAM\", goals: 8),\n  PlayerModel(name: \"Lionel Messi\", position: \"RW\", goals: 15),\n  // Many more players ...\n]\n\nlet fuzzyCachedPlayers =\n  players.map { player in \n    CachedFuzzySearchable(wrapping: player) \n  }\n\nfuzzyCachedPlayers.fuzzyMatch(\"di\")\n\n// Subsequente calls to 'fuzzyMatch' over the array above cause less overhead when re-matching\nfuzzyCachedPlayers.fuzzyMatch(\"di\") // Runs in about half time\n\nplayers.fuzzyMatch(\"di\") // Will fuzzy-match against original, non-cached PlayerModel values.\n```\n\n`CachedFuzzySearchable` has storage needs of a little over 2x that of the `fuzzyStringToSearch` property of the wrapped `FuzzySearchable` value. Discarding a `CachedFuzzySearchable` value also discards the extra memory that was allocated.\n\nReturning a different value from the wrapped `FuzzySearchable`'s `fuzzyStringToSearch` property resets the cache automatically during the next `fuzzyMatch` call and the overhead is reset to that of a fresh `CachedFuzzySearchable` instance, so implementers shouldn't worry about mantaining a stable `fuzzyStringToSearch` return.\n\n## License\n\nFuzzySearch is released under the [MIT](LICENSE) license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviktorasl%2Ffuzzysearch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fviktorasl%2Ffuzzysearch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviktorasl%2Ffuzzysearch/lists"}