SQLite全文搜索目录

发布于 2024-10-08 22:38:36 字数 165 浏览 0 评论 0原文

我想知道 fts(3/4) 对于 SQLite 是否可以实现以下功能。 我使用 fts3 创建了一个包含一些数据的表。

例如,如果我搜索 e*,我会得到以 ^e 开头的所有内容 但我也可以在索引/目录中搜索以 e 开头的特定单词吗?

这样我只能得到该词的结果,例如;艾略特,埃洛,呃。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

回首观望 2024-10-15 22:38:36

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

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

将返回文档包含以“lin”开头的单词。您只想要匹配的单词,而不想要上下文?也许“片段”功能会对您有所帮助。您可能会发现感兴趣的线程:

http://www.mail-archive.com/sqlite-users@sqlite.org/msg49345.html" mail-archive.com/[电子邮件受保护]/msg49345.html

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/[email protected]/msg49345.html

森末i 2024-10-15 22:38:36

FTS 引擎通过 offsets 虚拟函数提供该信息。

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

正如文档所说:

对于使用全文索引的 SELECT 查询,offsets() 函数返回一个包含一系列空格分隔整数的文本值。对于当前行的每个短语匹配中的每个术语,返回的列表中有四个整数。每组四个整数解释如下:

  1. 术语实例出现的列号(0 表示 FTS 表最左边的列,1 表示下一个最左边的列,依此类推)。
  2. 全文查询表达式中匹配术语的术语编号。查询表达式中的术语按照出现的顺序从 0 开始编号。
  3. 列中匹配项的字节偏移量。
  4. 匹配项的大小(以字节为单位)。

如何提取该信息取决于您以及如何将代码与 SQLite 集成。

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.

━╋う一瞬間旳綻放 2024-10-15 22:38:36

代码片段函数的文档关于其第六个参数相当模糊,因为该算法使用了最佳-score 方法来查找片段。

尽管如此,在我的申请中,我得到了我正在寻找的请求的原始条款的清晰摘录:

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

它可能对您的情况有所帮助;这个数据库内解决方案帮助了我,因为我不想提取位于数据库外部的代码中的术语。如果您正在搜索单个单词(MATCH 查询中没有空格、OR、..),它会起作用

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文