SQLite full text search catalog

為{幸葍}努か 提交于 2019-12-01 13:07:22

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

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.

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)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!