It looks like you can get this information using the offsets
helper function. Here is a link to more complete documentation:
4.1. Offset function
Basically you add a function to your query and it will return the offsets in the document.
SELECT offsets(data) FROM data ...
Each result is a list, separated by a space of 4 integers. The third column is the byte offset of the matching term within the column. You should be able to create a solution with this information.
Here is a transcript of some search queries.
sqlite> create virtual table data using fts4(body); sqlite> insert into data(body) values('the quick brown fox jumps over the lazy dog'); sqlite> insert into data(body) values('the lazy brown fox quickly jumps over the lazy dog'); sqlite> select * from data where body match 'lazy'; the quick brown fox jumps over the lazy dog the lazy brown fox quickly jumps over the lazy dog sqlite> select rowid,offsets(data) from data where body match 'brown'; 1|0 0 10 5 2|0 0 9 5 sqlite> select rowid,offsets(data) from data where body match 'lazy'; 1|0 0 35 4 2|0 0 4 4 0 0 42 4
So, if you want to search brown and lazy, both of these documents are the same.
In the first document, brown is 10, and lazy is 35. They are 25.
For the second document, brown is 9, and lazy is 4 and 42. They are 5 and 33 from each other.
They also refer to the ordering of the predicate, although it does not work when I try to combine two terms in the same query. I'm not sure if I misunderstand, or if I just don't know the right semantics.
I suspect that there are some SQL pivot syntagans that can be used to perform all ranking calculations in sqlite. Getting results from sqlite and just doing the math ranking itself are probably more serviceable.
source share