{"action":"created","issue":{"url":"https://api.github.com/repos/stephencelis/SQLite.swift/issues/367","repository_url":"https://api.github.com/repos/stephencelis/SQLite.swift","labels_url":"https://api.github.com/repos/stephencelis/SQLite.swift/issues/367/labels{/name}","comments_url":"https://api.github.com/repos/stephencelis/SQLite.swift/issues/367/comments","events_url":"https://api.github.com/repos/stephencelis/SQLite.swift/issues/367/events","html_url":"https://github.com/stephencelis/SQLite.swift/issues/367","id":138531778,"number":367,"title":"What would be the best way to implement support for FTS \"snippet\" functionality.","user":{"login":"achansonjr","id":883177,"avatar_url":"https://avatars3.githubusercontent.com/u/883177?v=3","gravatar_id":"","url":"https://api.github.com/users/achansonjr","html_url":"https://github.com/achansonjr","followers_url":"https://api.github.com/users/achansonjr/followers","following_url":"https://api.github.com/users/achansonjr/following{/other_user}","gists_url":"https://api.github.com/users/achansonjr/gists{/gist_id}","starred_url":"https://api.github.com/users/achansonjr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/achansonjr/subscriptions","organizations_url":"https://api.github.com/users/achansonjr/orgs","repos_url":"https://api.github.com/users/achansonjr/repos","events_url":"https://api.github.com/users/achansonjr/events{/privacy}","received_events_url":"https://api.github.com/users/achansonjr/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-03-04T17:22:56Z","updated_at":"2017-05-04T17:27:10Z","closed_at":null,"body":"SQLite when using the FTS3/4 extensions can support the concept of a snippet. Essentially the snippet is a subset of the indexed column, that has html bold tags surrounding the matched terms.\n\nSource information here: https://www.sqlite.org/fts3.html#section_4_2\n\nSo using the example from the above link, a snippet query it might look something like:\n\n``` sql\nSELECT snippet(text) FROM text WHERE text MATCH 'cold';\n```\n\nI have successfully used the VirtualTable implementation to retrieve matching records using the `.match(string: String)` function, but would like to be able to select the snippet as well.\n\nMy current implementation attempt is:\n\n``` swift\nlet db = try? Connection(\"table.database\")\nlet indexTable = VirtualTable(\"fts_index\")\nlet guidField = Expression<String>(\"object_guid\")\nlet contentsField = Expression<String>(\"contents\")\nlet snippet = Expression<String>(\"snippet(contents)\")\nlet _ = try? db?.run(indexTable.create(.FTS4(guidField, contentsField)))\n\nlet matchQuery: QueryType =indexTable.select(snippet, guidField, contentsField).match(\"cold\")\nlet results = try? db?.prepare(matchQuery)\n\nif let concreteResults = results {\n  let _ = concreteResults.flatMap( { \n    print(\"\\($0[guidField]), \\($0[snippet]), \\($0[contentsField])\")\n  })\n}\n```\n\nI get what I expect for both guidField and contentsField, yet the result of snippet is something puzzling.\n\n``` text\n3771714D-19AB-464B-80E2-6C5A798D8104, snippet(Expression<String>(template: \"\\\"contents\\\"\", bindings: [])), This is a cold record\n```\n\nI imagine I just need a custom expression, but I am not sure how to implement custom SQLite functions, or else I may just be missing it in the docs.\n\nThanks for any help, and I would be glad once I know how to implement this for both the `snippet` and `matchInfo` capability in SQLite.\n\nThanks, awesome library and really enjoying using it.\n"},"comment":{"url":"https://api.github.com/repos/stephencelis/SQLite.swift/issues/comments/299253589","html_url":"https://github.com/stephencelis/SQLite.swift/issues/367#issuecomment-299253589","issue_url":"https://api.github.com/repos/stephencelis/SQLite.swift/issues/367","id":299253589,"user":{"login":"stephanheilner","id":2056085,"avatar_url":"https://avatars0.githubusercontent.com/u/2056085?v=3","gravatar_id":"","url":"https://api.github.com/users/stephanheilner","html_url":"https://github.com/stephanheilner","followers_url":"https://api.github.com/users/stephanheilner/followers","following_url":"https://api.github.com/users/stephanheilner/following{/other_user}","gists_url":"https://api.github.com/users/stephanheilner/gists{/gist_id}","starred_url":"https://api.github.com/users/stephanheilner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stephanheilner/subscriptions","organizations_url":"https://api.github.com/users/stephanheilner/orgs","repos_url":"https://api.github.com/users/stephanheilner/repos","events_url":"https://api.github.com/users/stephanheilner/events{/privacy}","received_events_url":"https://api.github.com/users/stephanheilner/received_events","type":"User","site_admin":false},"created_at":"2017-05-04T17:27:10Z","updated_at":"2017-05-04T17:27:10Z","body":"@jberkel Did you ever come up with a working solution to get the snippet (or highlight) with FTS5?"}}
{"actor":{"display_login":"stephanheilner"}}