SQLite - 在文本字段中提取单个单词

SQLite - Extracting a single word in a text field

我有一个充满纯文本的数据库。我想要一个查询来找到一些与特定子词相似的词。比如建议或猜测。

this is a database filled with data.

我要找的子词是da.

现在查询的结果应该只是一列单个单词,例如:

database
data

首先您需要找到匹配 'da' 的行。您可以使用 LIKE '%da%'REGEXP 'da' 之类的东西(参见 this SO answer to know how to install REGEXP extension)。

然后你应该提取与你的模式'da'对应的词。这就是 SQLite 无法直接解决的地方。在其他 DBMS 中,您有类似 substring(string from pattern) 的函数(例如 in PostgreSQL)。你在SQLite中没有那种功能。

您可以在与此 extension-functions.c file in the contribs or this regexp operator for SQLite 中的功能相同的基础上开发这样的功能。但是这里你不需要运算符,而是 returns 匹配的函数。我还没有找到现有的扩展。

也许您可以使用 SQLite Full-Text Search extension 分词器来提取您想要的词。