summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--database.h32
1 files changed, 27 insertions, 5 deletions
diff --git a/database.h b/database.h
index 7e7aa95..7d61507 100644
--- a/database.h
+++ b/database.h
@@ -152,6 +152,7 @@ static inline int dbVersion(sqlite3 *db) {
 
 static const char *InitSQL = SQL(
 	BEGIN TRANSACTION;
+
 	CREATE TABLE contexts (
 		context INTEGER PRIMARY KEY,
 		network TEXT NOT NULL,
@@ -159,6 +160,7 @@ static const char *InitSQL = SQL(
 		query BOOLEAN NOT NULL,
 		UNIQUE (network, name)
 	);
+
 	CREATE TABLE names (
 		name INTEGER PRIMARY KEY,
 		nick TEXT NOT NULL,
@@ -166,6 +168,7 @@ static const char *InitSQL = SQL(
 		host TEXT NOT NULL,
 		UNIQUE (nick, user, host)
 	);
+
 	CREATE TABLE events (
 		event INTEGER PRIMARY KEY,
 		time DATETIME NOT NULL,
@@ -175,19 +178,38 @@ static const char *InitSQL = SQL(
 		target TEXT,
 		message TEXT
 	);
+
+	CREATE VIEW text (
+		event, network, channel, query, nick, user, target, message
+	) AS
+	SELECT
+		event, network,
+		CASE WHEN query THEN NULL ELSE contexts.name END,
+		CASE WHEN query THEN contexts.name ELSE NULL END,
+		nick, user, target, message
+	FROM events
+	JOIN contexts USING (context)
+	JOIN names ON names.name = events.name;
+
 	CREATE VIRTUAL TABLE search USING fts5 (
-		message,
-		content = events,
+		network, channel, query, nick, user, target, message,
+		content = text,
 		content_rowid = event,
 		tokenize = 'porter'
 	);
+
 	CREATE TRIGGER eventsInsert AFTER INSERT ON events BEGIN
-		INSERT INTO search (rowid, message) VALUES (new.event, new.message);
+		INSERT INTO search (
+			rowid, network, channel, query, nick, user, target, message
+		) SELECT * FROM text WHERE event = new.event;
 	END;
+
 	CREATE TRIGGER eventsDelete AFTER DELETE ON events BEGIN
-		INSERT INTO search (search, rowid, message)
-		VALUES ('delete', old.event, old.message);
+		INSERT INTO search (
+			search, rowid, network, channel, query, nick, user, target, message
+		) SELECT 'delete', * FROM text WHERE event = old.event;
 	END;
+
 	COMMIT TRANSACTION;
 );
 
git: update to 1.8.3John Keeping 2013-05-22cache.c: cache ls_cache output properlyJohn Keeping 2013-05-22tests: introduce strip_header() helper functionJohn Keeping 2013-05-22shared.c: use die_errno() where appropriateJohn Keeping 2013-05-22html.c: die when write failsJohn Keeping 2013-05-22ui-log: add <span/> around commit decorationsJohn Keeping 2013-05-22Makefile: fix parallel "make test"John Keeping 2013-05-18cache.c: fix cache_lsJohn Keeping 2013-05-13t0109: "function" is a bash-ismJohn Keeping 2013-05-13New mailing list.Jason A. Donenfeld 2013-04-30ui-snapshot: do not access $HOMEJason A. Donenfeld 2013-04-27t0001: validate Git -rcN version numbers correctlyJohn Keeping 2013-04-27git: update to 1.8.2.2John Keeping 2013-04-17scan-tree: fix regression in section-from-path=-1John Keeping 2013-04-15t0001: ignore ".dirty" suffix on Git versionJohn Keeping 2013-04-15tests: set TEST_OUTPUT_DIRECTORY to the CGit test directoryJohn Keeping 2013-04-15t0109: test more URLsJohn Keeping 2013-04-10cgitrc.5.txt: Specify when scan-path must be defined before.Jason A. Donenfeld 2013-04-10ui-snapshot.c: Prepend "V" when guessing ref namesLukas Fleischer 2013-04-10t0107: Skip ZIP tests if unzip(1) isn't availableLukas Fleischer 2013-04-10tests/: Do not use `sed -i`Lukas Fleischer 2013-04-10Add branch-sort and repo.branch-sort options.Jason A. Donenfeld 2013-04-10t0109: chain operations with &&John Keeping 2013-04-10cgit.c: Do not restore unset environment variablesLukas Fleischer 2013-04-09t0107: Use `tar -z` for gzip'ed archivesLukas Fleischer