Add FTS snippet functionality
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start with the VirtualTable, Expression, and QueryType APIs used in the example, then trace how .match("cold") builds and selects expressions. Compare that behavior with SQLite FTS3/4 snippet and matchInfo queries. Done means callers can select these FTS results and receive SQLite’s matched snippet or match information rather than a rendered expression description.
Written by the indexing model from the issue text.
Description
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.
Source information here: https://www.sqlite.org/fts3.html#section_4_2
So using the example from the above link, a snippet query it might look something like:
SELECT snippet(text) FROM text WHERE text MATCH 'cold';
I 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.
My current implementation attempt is:
let db = try? Connection("table.database")
let indexTable = VirtualTable("fts_index")
let guidField = Expression<String>("object_guid")
let contentsField = Expression<String>("contents")
let snippet = Expression<String>("snippet(contents)")
let _ = try? db?.run(indexTable.create(.FTS4(guidField, contentsField)))
let matchQuery: QueryType =indexTable.select(snippet, guidField, contentsField).match("cold")
let results = try? db?.prepare(matchQuery)
if let concreteResults = results {
let _ = concreteResults.flatMap( {
print("\($0[guidField]), \($0[snippet]), \($0[contentsField])")
})
}
I get what I expect for both guidField and contentsField, yet the result of snippet is something puzzling.
3771714D-19AB-464B-80E2-6C5A798D8104, snippet(Expression<String>(template: "\"contents\"", bindings: [])), This is a cold record
I 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.
Thanks for any help, and I would be glad once I know how to implement this for both the snippet and matchInfo capability in SQLite.
Thanks, awesome library and really enjoying using it.
- Dominant language
- Swift
- Stars
- 10.2k
- Forks
- 1.6k
- Avg merge
- 6d 2h
- Merged PRs (30d)
- 2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from stephencelis/SQLite.swift
-
Difficulty 1/5 Under an hour Newbie friendliness 95/100
stephencelis/SQLite.swift#1375 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
stephencelis/SQLite.swift#1293 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 38/100
stephencelis/SQLite.swift#1347 · 7 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
stephencelis/SQLite.swift#1338 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
stephencelis/SQLite.swift#1337 · 3 comments ·
All issues in stephencelis/SQLite.swift
Similar issues
-
tvOS
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
skiptools/skip-fuse-ui#147 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
OneBusAway/onebusaway-ios#1438 · 1 reaction ·