如何从 FTS3 表搜索中排除列

发布于 2024-09-27 02:48:39 字数 414 浏览 0 评论 0原文

我有这样的表:

CREATE VIRTUAL TABLE t USING FTS3(hidden, text1, text2)

我希望用户能够搜索“text1”和“text2”列,因此查询是

SELECT docid FROM t WHERE t MATCH ?

可能的请求是:

SELECT docid FROM t WHERE t MATCH 'foo'
SELECT docid FROM t WHERE t MATCH 'text1:foo OR text2:bar'

问:如何从搜索中排除“隐藏”列,以便用户可以找不到按隐藏值的行?

我将使用“隐藏”列来引用辅助表中包含附加信息的行。

I have such table:

CREATE VIRTUAL TABLE t USING FTS3(hidden, text1, text2)

I would like user to be able to searh over 'text1' and 'text2' columns, so the query is

SELECT docid FROM t WHERE t MATCH ?

And possible requests are:

SELECT docid FROM t WHERE t MATCH 'foo'
SELECT docid FROM t WHERE t MATCH 'text1:foo OR text2:bar'

Q: how can I exclude 'hidden' column from search, so that user can't find rows by hidden value?

I am going to use 'hidden' column to refer to rows in secondary table with additional information.

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

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

发布评论

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

评论(2

情深缘浅 2024-10-04 02:48:39

旧线程,但如果您使用的是较新版本的 SQLite (> 3.8),您现在可以使用 notindexed 选项,例如:

CREATE VIRTUAL TABLE t USING FTS4(uuid, document, notindexed=uuid);

这将从匹配查询中排除该列。

我还通过嵌入我自己构建的 SQLite 3.8 在 iOS 上实现了此功能。

notindexed 选项的文档

Old thread, but if you're using a newer build of SQLite (> 3.8), you can now use the notindexed option, e.g.:

CREATE VIRTUAL TABLE t USING FTS4(uuid, document, notindexed=uuid);

This will exclude the column from match queries.

I've also got this working on iOS by embedding my own build of SQLite 3.8.

Documentation for notindexed option

末蓝 2024-10-04 02:48:39

FTS3 表有一个名为 docid 的免费 64 位整数列,该列未建立索引。只需将其他数据放入单独的表中,其中该表的主键与 FTS3 表的 docid 相同。

CREATE VIRTUAL TABLE t USING FTS3(text1, text2);

CREATE TABLE additional (id INTEGER PRIMARY KEY, hidden VARCHAR);

INSERT INTO t (docid, text1, text2) VALUES (243, 'foo', 'bar');
INSERT INTO additional VALUES (243, 'bas');

SELECT docid, text1, text2, hidden FROM t JOIN additional ON t.docid = additional.id WHERE t MATCH 'foo';

An FTS3 table gets a free 64 bit integer column called docid which is not indexed. Simply put additional data in a separate table where the Primary Key for that table is the same as the docid for the FTS3 table.

CREATE VIRTUAL TABLE t USING FTS3(text1, text2);

CREATE TABLE additional (id INTEGER PRIMARY KEY, hidden VARCHAR);

INSERT INTO t (docid, text1, text2) VALUES (243, 'foo', 'bar');
INSERT INTO additional VALUES (243, 'bas');

SELECT docid, text1, text2, hidden FROM t JOIN additional ON t.docid = additional.id WHERE t MATCH 'foo';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文