SQLite full text search catalog

2020-03-30 06:00发布

I wonder if the following is possible with fts(3/4) for SQLite. I created a table with some data using fts3.

If i for example search for e* i get everything that starts with ^e But can i also search the index/catalog for the specific words that starts with e?

So that i only get the results of that words back like; elliot, elo,eehh.

3条回答
在下西门庆
2楼-- · 2020-03-30 06:18

the documentation of the snippet function is rather vague regarding its 6th parameter because the algorithm uses a best-score approach to find the snippet.

Nevertheless in my application i get a clean extract of the original terms I am looking for with the request :

select snippet(docs,'','','', -1, 1) from docs where docs match 'e*';

It may help in your case ; this in-database solution helped me because i didn't want to extract the terms in code located outside of the db. It works if you are searching for single words (no space, OR, .. in the MATCH query)

查看更多
甜甜的少女心
3楼-- · 2020-03-30 06:21

http://www.sqlite.org/fts3.html#section_3

       SELECT * FROM docs WHERE docs MATCH 'lin*';

Will return the docs that contain a word starting with "lin". You only want the words that match, not the context? Maybe the "snippets" feature will help you. And you may find this thread of interest:

http://www.mail-archive.com/sqlite-users@sqlite.org/msg49345.html

查看更多
走好不送
4楼-- · 2020-03-30 06:32

The FTS engine provides that information via the offsets virtual function.

SELECT offsets(docs) FROM docs WHERE docs MATCH 'e*';

As the documentation says:

For a SELECT query that uses the full-text index, the offsets() function returns a text value containing a series of space-separated integers. For each term in each phrase match of the current row, there are four integers in the returned list. Each set of four integers is interpreted as follows:

  1. The column number that the term instance occurs in (0 for the leftmost column of the FTS table, 1 for the next leftmost, etc.).
  2. The term number of the matching term within the full-text query expression. Terms within a query expression are numbered starting from 0 in the order that they occur.
  3. The byte offset of the matching term within the column.
  4. The size of the matching term in bytes.

How to extract that information is up to you and how you integrate your code with SQLite.

查看更多
登录 后发表回答