{"id":24537849,"url":"https://github.com/aayush9029/searchkit","last_synced_at":"2025-06-12T15:06:48.805Z","repository":{"id":272854541,"uuid":"917968923","full_name":"Aayush9029/SearchKit","owner":"Aayush9029","description":"A lightweight Swift library providing robust and efficient text-search utilities.","archived":false,"fork":false,"pushed_at":"2025-05-10T22:40:36.000Z","size":19,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-10T23:23:39.666Z","etag":null,"topics":["search-algorithm","string-matching","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Aayush9029.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2025-01-17T01:41:45.000Z","updated_at":"2025-05-10T22:40:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"5b52fbb5-d4c8-4a8c-9a85-d5c89a108f05","html_url":"https://github.com/Aayush9029/SearchKit","commit_stats":null,"previous_names":["aayush9029/searchkit"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Aayush9029/SearchKit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aayush9029%2FSearchKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aayush9029%2FSearchKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aayush9029%2FSearchKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aayush9029%2FSearchKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Aayush9029","download_url":"https://codeload.github.com/Aayush9029/SearchKit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aayush9029%2FSearchKit/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259490544,"owners_count":22865766,"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":["search-algorithm","string-matching","swift"],"created_at":"2025-01-22T14:14:04.555Z","updated_at":"2025-06-12T15:06:48.797Z","avatar_url":"https://github.com/Aayush9029.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\u003cimg src=\"https://github.com/user-attachments/assets/b87ca842-14b7-4e33-9fdc-d564b7bb7220\" width=\"128\"\u003e\n    \n\n\u003ch1\u003e SearchKit \u003c/h1\u003e\n\nSearchKit is a Swift library for efficient string search operations, combining **Knuth-Morris-Pratt (KMP)**, **Boyer-Moore**, and **Levenshtein Distance** algorithms for robust exact and fuzzy searches.\n\n\n\u003c/div\u003e\n\n---\n\n## Features\n\n- **KMP**: Fast substring search ([Wikipedia](https://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm)).\n- **Boyer-Moore**: Skips unnecessary comparisons ([Wikipedia](https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string-search_algorithm)).\n- **Levenshtein Distance**: Measures edit distance ([Wikipedia](https://en.wikipedia.org/wiki/Levenshtein_distance)).\n- **Unicode Support**: Handles emojis and special characters.\n- **Concurrency**: Async/await for parallel searches.\n\n---\n\n## Installation\n\nAdd SearchKit via Swift Package Manager:\n\n```swift\n// swift-tools-version: 6.0\nimport PackageDescription\n\nlet package = Package(\n    name: \"YourProject\",\n    dependencies: [\n        .package(url: \"https://github.com/Aayush9029/SearchKit.git\", branch: \"main\")\n    ],\n    targets: [\n        .target(name: \"YourTarget\", dependencies: [\"SearchKit\"])\n    ]\n)\n```\n\n---\n\n## Examples\n\n### KMP Example\n\n```swift\nlet kmp = KMP(text: \"Hello, World!\")\ndo {\n    let index = try kmp.search(pattern: \"World\")\n    print(\"Found at index: \\(index)\")\n} catch {\n    print(\"Not found\")\n}\n```\n\n### Boyer-Moore Example\n\n```swift\nlet bm = BoyerMoore(text: \"Searching with Boyer-Moore\")\n\n// Find first occurrence\ndo {\n    let index = try bm.search(pattern: \"Boyer\")\n    print(\"Found at index: \\(index)\")\n} catch {\n    print(\"Not found\")\n}\n\n// Find all occurrences\nlet matches = bm.searchAll(pattern: \"e\")\nprint(\"Found at indices: \\(matches)\") // [1, 16]\n```\n\nThe Boyer-Moore implementation provides both single-match (`search`) and multi-match (`searchAll`) capabilities, making it versatile for different search requirements. The algorithm maintains its efficiency by using the bad character rule for pattern shifting.\n\n### Levenshtein Example\n\n```swift\nlet levenshtein = Levenshtein()\nTask {\n    let distance = await levenshtein.distance(\"kitten\", \"sitting\")\n    print(\"Distance: \\(distance)\")\n}\n```\n\n---\n\n## Testing\n\nRun tests to verify functionality:\n\n```sh\nswift test\n```\n\n---\n\n## License\n\nSearchKit is MIT licensed. See [LICENSE](LICENSE) for details.\n\n---\n\nHappy Searching! 🚀\n\n---\n\n### Levenshtein Distance\n\nThe `Levenshtein` struct provides efficient string similarity measurement using the Levenshtein distance algorithm. It includes two main functionalities:\n\n1. Calculate exact edit distance:\n```swift\nlet distance = Levenshtein.distance(source: \"kitten\", target: \"sitting\")\n// Returns: 3\n```\n\n2. Check if strings are within a specific edit distance (optimized):\n```swift\nlet isClose = Levenshtein.isWithinDistance(source: \"hello\", target: \"helo\", threshold: 1)\n// Returns: true\n```\n\nThe implementation uses space-optimized dynamic programming, requiring only O(min(m,n)) space where m and n are the lengths of the input strings. The time complexity is O(mn) for exact distance calculation, but the `isWithinDistance` method includes early termination optimizations for better performance when you only need to check if strings are within a certain edit distance.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faayush9029%2Fsearchkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faayush9029%2Fsearchkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faayush9029%2Fsearchkit/lists"}