parent
9bf5033c05
commit
90bf87b293
@ -0,0 +1,28 @@
|
||||
CREATE VIRTUAL TABLE news_resource_fts
|
||||
USING FTS4(
|
||||
tokenizer = porter,
|
||||
content = news_resources,
|
||||
news_resource_id TEXT NOT NULL,
|
||||
title TEXT NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
);
|
||||
-- Triggers to keep the FTS index up to date.
|
||||
CREATE TRIGGER news_resource_ai AFTER INSERT ON news_resource BEGIN
|
||||
INSERT INTO news_resource_fts (rowid, news_resource_id, title, content) VALUES (new.rowid, new.id, new.title, new.content);
|
||||
END;
|
||||
CREATE TRIGGER news_resource_ad AFTER DELETE ON news_resource BEGIN
|
||||
INSERT INTO news_resource_fts (news_resource_fts, rowid, news_resource_id, title, content) VALUES ('delete', old.rowid, old.id, old.title, old.content);
|
||||
END;
|
||||
CREATE TRIGGER news_resource_au AFTER UPDATE ON news_resource BEGIN
|
||||
INSERT INTO news_resource_fts (news_resource_fts, rowid, news_resource_id, title, content) VALUES ('delete', old.rowid, old.id, old.title, old.content);
|
||||
INSERT INTO news_resource_fts (rowid, news_resource_id, title, content) VALUES (new.rowid, new.id, new.title, new.content);
|
||||
END;
|
||||
|
||||
insertAll:
|
||||
INSERT INTO news_resource_fts (news_resource_id, title, content) SELECT id, title, content FROM news_resource;
|
||||
|
||||
searchAllNewsResources:
|
||||
SELECT news_resource_id FROM news_resource_fts WHERE news_resource_fts MATCH :query;
|
||||
|
||||
getCount:
|
||||
SELECT count(*) FROM news_resource_fts;
|
||||
@ -0,0 +1,11 @@
|
||||
CREATE TABLE IF NOT EXISTS news_resource_topic (
|
||||
news_resource_id TEXT NOT NULL,
|
||||
topic_id TEXT NOT NULL,
|
||||
PRIMARY KEY(news_resource_id, topic_id),
|
||||
FOREIGN KEY(news_resource_id) REFERENCES news_resource(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY(topic_id) REFERENCES topic(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS index_news_resource_topic_news_resource_id ON news_resource_topic(news_resource_id);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS index_news_resource_topic_topic_id ON news_resource_topic(topic_id);
|
||||
@ -0,0 +1,11 @@
|
||||
CREATE TABLE IF NOT EXISTS news_resources_topics (
|
||||
news_resource_id TEXT NOT NULL,
|
||||
topic_id TEXT NOT NULL,
|
||||
PRIMARY KEY (news_resource_id, topic_id),
|
||||
FOREIGN KEY (news_resource_id) REFERENCES news_resource(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (topic_id) REFERENCES topic(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX idx_news_resource_id ON news_resource_topic(news_resource_id);
|
||||
|
||||
CREATE INDEX idx_topic_id ON news_resource_topic(topic_id);
|
||||
@ -1,11 +0,0 @@
|
||||
CREATE TABLE IF NOT EXISTS news_resources_topics (
|
||||
news_resource_id TEXT NOT NULL,
|
||||
topic_id TEXT NOT NULL,
|
||||
PRIMARY KEY(news_resource_id, topic_id),
|
||||
FOREIGN KEY(news_resource_id) REFERENCES news_resources(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY(topic_id) REFERENCES topics(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS index_news_resources_topics_news_resource_id ON news_resources_topics(news_resource_id);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS index_news_resources_topics_topic_id ON news_resources_topics(topic_id);
|
||||
@ -1,28 +0,0 @@
|
||||
CREATE VIRTUAL TABLE news_resources_fts
|
||||
USING FTS4(
|
||||
tokenizer = porter,
|
||||
content = news_resources,
|
||||
news_resource_id TEXT NOT NULL,
|
||||
title TEXT NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
);
|
||||
-- Triggers to keep the FTS index up to date.
|
||||
CREATE TRIGGER news_resources_ai AFTER INSERT ON news_resources BEGIN
|
||||
INSERT INTO news_resources_fts (rowid, news_resource_id, title, content) VALUES (new.rowid, new.id, new.title, new.content);
|
||||
END;
|
||||
CREATE TRIGGER news_resources_ad AFTER DELETE ON news_resources BEGIN
|
||||
INSERT INTO news_resources_fts (news_resources_fts, rowid, news_resource_id, title, content) VALUES ('delete', old.rowid, old.id, old.title, old.content);
|
||||
END;
|
||||
CREATE TRIGGER news_resources_au AFTER UPDATE ON news_resources BEGIN
|
||||
INSERT INTO news_resources_fts (news_resources_fts, rowid, news_resource_id, title, content) VALUES ('delete', old.rowid, old.id, old.title, old.content);
|
||||
INSERT INTO news_resources_fts (rowid, news_resource_id, title, content) VALUES (new.rowid, new.id, new.title, new.content);
|
||||
END;
|
||||
|
||||
insertAll:
|
||||
INSERT INTO news_resources_fts (news_resource_id, title, content) SELECT id, title, content FROM news_resources;
|
||||
|
||||
searchAllNewsResources:
|
||||
SELECT news_resource_id FROM news_resources_fts WHERE news_resources_fts MATCH :query;
|
||||
|
||||
getCount:
|
||||
SELECT count(*) FROM news_resources_fts;
|
||||
@ -1,11 +0,0 @@
|
||||
CREATE TABLE IF NOT EXISTS news_resources_topics (
|
||||
news_resource_id TEXT NOT NULL,
|
||||
topic_id TEXT NOT NULL,
|
||||
PRIMARY KEY (news_resource_id, topic_id),
|
||||
FOREIGN KEY (news_resource_id) REFERENCES news_resources(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (topic_id) REFERENCES topics(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX idx_news_resource_id ON news_resources_topics(news_resource_id);
|
||||
|
||||
CREATE INDEX idx_topic_id ON news_resources_topics(topic_id);
|
||||
@ -1,14 +1,14 @@
|
||||
CREATE TABLE recent_search_queries (
|
||||
CREATE TABLE recent_search_query (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
query TEXT NOT NULL,
|
||||
queried_date INTEGER DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
getRecentSearchQueryEntities:
|
||||
SELECT * FROM recent_search_queries ORDER BY queried_date DESC LIMIT :limit;
|
||||
SELECT * FROM recent_search_query ORDER BY queried_date DESC LIMIT :limit;
|
||||
|
||||
insertOrReplaceRecentSearchQuery:
|
||||
INSERT OR REPLACE INTO recent_search_queries (query) VALUES (:query);
|
||||
INSERT OR REPLACE INTO recent_search_query (query) VALUES (:query);
|
||||
|
||||
clearRecentSearchQueries:
|
||||
DELETE FROM recent_search_queries;
|
||||
DELETE FROM recent_search_query;
|
||||
|
||||
Loading…
Reference in new issue