sqlite - SQLite:编辑字段,全文已更新?

标签 sqlite full-text-search

在SQLite 3中

如果我更新具有全文索引的字段,则全文索引会被更新,还是需要手动更新它?

最佳答案

取决于,例如。
如果您使用的是“外部内容FTS4表”,它将不会自动更新。

来自http://www.sqlite.org/fts3.html#section_6_2_2

CREATE TABLE t2(id INTEGER PRIMARY KEY, a, b, c, d);
CREATE VIRTUAL TABLE t3 USING fts4(content="t2", b, c);

INSERT INTO t2 VALUES(2, 'a b', 'c d', 'e f');
INSERT INTO t2 VALUES(3, 'g h', 'i j', 'k l');
INSERT INTO t3(docid, b, c) SELECT id, b, c FROM t2;
-- The following query returns a single row with two columns containing
-- the text values "i j" and "k l".
--
-- The query uses the full-text index to discover that the MATCH 
-- term matches the row with docid=3. It then retrieves the values
-- of columns b and c from the row with rowid=3 in the content table
-- to return.
--
SELECT * FROM t3 WHERE t3 MATCH 'k';

-- Following the UPDATE, the query still returns a single row, this
-- time containing the text values "xxx" and "yyy". This is because the
-- full-text index still indicates that the row with docid=3 matches
-- the FTS4 query 'k', even though the documents stored in the content
-- table have been modified.
--
UPDATE t2 SET b = 'xxx', c = 'yyy' WHERE rowid = 3;
SELECT * FROM t3 WHERE t3 MATCH 'k';


但也可以通过触发器解决。


而不是分别写入全文索引和内容
表,一些用户可能希望使用数据库触发器来保持
关于存储的文档集的最新全文索引
在内容表中。例如,使用之前的表格
例子:

关于sqlite - SQLite:编辑字段,全文已更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11354050/

相关文章:

sqlite - PostgreSQL 中 SQLite 日期时间函数的等价物是什么?

java - Android SQLite 从数据库中删除特定行

javascript - 客户端 JavaScript 中的 Stackoverflow "related entries"算法?

sql-server - SQL 问题 : Using CONTAINS() doesn't work, 但 LIKE 工作正常

mysql - 全文 InnoDB 搜索没有响应

c# - 有没有一种方法可以按查询所采用的表中的列的顺序来对 sqlite PRAGMAforeign_key_list() 查询的结果进行排序?

ios - 自定义 SQLite 排序规则未触发

android - 没有这样的列名 sqlite android

java - Apache Lucene createFullTextQuery 返回匹配的空对象

regex - Sqlite3 FTS : Limiting length of items between two words in match request?