{"id":50376950,"url":"https://github.com/twn39/jiebafts5","last_synced_at":"2026-05-30T10:01:48.172Z","repository":{"id":357567247,"uuid":"1237525191","full_name":"twn39/jiebafts5","owner":"twn39","description":"A Swift Package that integrates cppjieba with GRDB as a custom FTS5 tokenizer, enabling high-quality Chinese full-text search in SQLite on iOS and macOS.","archived":false,"fork":false,"pushed_at":"2026-05-13T09:18:02.000Z","size":2124,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-13T11:21:22.488Z","etag":null,"topics":["cpp","fts5","full-text-search","grdb","ios","jieba","sqlite3","swift","tokenizer"],"latest_commit_sha":null,"homepage":"","language":"C++","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/twn39.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":"2026-05-13T09:05:01.000Z","updated_at":"2026-05-13T09:22:16.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/twn39/jiebafts5","commit_stats":null,"previous_names":["twn39/jiebafts5"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/twn39/jiebafts5","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twn39%2Fjiebafts5","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twn39%2Fjiebafts5/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twn39%2Fjiebafts5/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twn39%2Fjiebafts5/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twn39","download_url":"https://codeload.github.com/twn39/jiebafts5/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twn39%2Fjiebafts5/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33687722,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-30T02:00:06.278Z","response_time":92,"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":["cpp","fts5","full-text-search","grdb","ios","jieba","sqlite3","swift","tokenizer"],"created_at":"2026-05-30T10:01:47.264Z","updated_at":"2026-05-30T10:01:48.164Z","avatar_url":"https://github.com/twn39.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JiebaFTS5\n\nA Swift Package that integrates [cppjieba](https://github.com/yanyiwu/cppjieba) with [GRDB](https://github.com/groue/GRDB.swift) as a custom FTS5 tokenizer, enabling high-quality Chinese full-text search in SQLite on iOS and macOS.\n\n## Features\n\n- **Jieba word segmentation** — accurate Chinese tokenization via cppjieba's MixSeg (MP + HMM) and QuerySeg algorithms\n- **COLOCATED synonym indexing** — sub-words (`清华`, `大学`) are indexed alongside the full compound (`清华大学`), enabling partial-word search without false positives (FTS5 Method 3)\n- **Zero-copy token emission** — tokens are emitted directly from SQLite's own buffer with no intermediate heap allocation\n- **Case folding** — optional ASCII/Latin lowercasing, with a stack-buffer fast path for uppercase ASCII and Unicode-aware folding for full-width characters\n- **Memory-efficient** — one shared cppjieba engine (~25 MB) across all `DatabasePool` connections via a process-lifetime singleton\n- **Thread-safe** — `static let` initialisation; all post-init C calls are read-only\n\n## Usage\n\n### 1. Register the tokenizer\n\n```swift\nimport GRDB\nimport JiebaFTS5\n\nvar config = Configuration()\nconfig.addJiebaTokenizer()\n\nlet dbPool = try DatabasePool(path: path, configuration: config)\n```\n\n### 2. Create an FTS5 virtual table\n\n```swift\ntry dbPool.write { db in\n    try db.create(virtualTable: \"articles\", using: FTS5()) { t in\n        t.tokenizer = .jieba()          // caseFolding: true (default)\n        t.column(\"title\")\n        t.column(\"body\")\n    }\n}\n```\n\n### 3. Insert and search\n\n```swift\n// Insert\ntry dbPool.write { db in\n    try db.execute(\n        sql: \"INSERT INTO articles (title, body) VALUES (?, ?)\",\n        arguments: [\"清华大学\", \"清华大学是中国顶尖高校之一。\"]\n    )\n}\n\n// Search — matches \"清华大学\", \"清华\", \"大学\", \"华大\"\ntry dbPool.read { db in\n    let pattern = FTS5Pattern(matchingPhrase: \"清华\")\n    let rows = try Row.fetchAll(\n        db,\n        sql: \"SELECT * FROM articles WHERE articles MATCH ?\",\n        arguments: [pattern]\n    )\n}\n```\n\n### 4. Case-sensitive search\n\n```swift\nt.tokenizer = .jieba(caseFolding: false)\n```\n\n### 5. Snippet highlighting\n\n```swift\nlet sql = \"\"\"\n    SELECT snippet(articles, 0, '\u003c\u003c', '\u003e\u003e', '...', 10)\n    FROM articles WHERE articles MATCH ?\n    \"\"\"\nlet snippet = try db.read { db in\n    try String.fetchOne(db, sql: sql, arguments: [FTS5Pattern(matchingPhrase: \"清华大学\")])\n}\n// \"\u003c\u003c清华大学\u003e\u003e是中国顶尖高校之一。\"\n```\n\n### 6. Preheat on app launch\n\nThe engine takes 100–300 ms to initialise. Call `preheat()` at launch to avoid latency on the first search:\n\n```swift\n// SwiftUI\n@main struct MyApp: App {\n    init() { JiebaEngine.preheat() }\n}\n\n// UIKit\nfunc application(_ application: UIApplication,\n                 didFinishLaunchingWithOptions launchOptions: ...) -\u003e Bool {\n    JiebaEngine.preheat()\n    return true\n}\n```\n\n## License\n\nMIT — see [LICENSE](LICENSE).\n\nBundles [cppjieba](https://github.com/yanyiwu/cppjieba) and [limonp](https://github.com/yanyiwu/limonp) (both MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwn39%2Fjiebafts5","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwn39%2Fjiebafts5","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwn39%2Fjiebafts5/lists"}