summary refs log tree commit diff
path: root/search.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-07-11 18:07:33 -0400
committerJune McEnroe <june@causal.agency>2020-07-11 18:07:33 -0400
commit5d857422687068526d6477073ef83630ffcf0c1e (patch)
tree0ccc0a277ca4166bdd0d007bf7bee1f6a4393bab /search.c
parentHandle KCGI_EXIT and call khttp_fcgi_free (diff)
downloadscooper-5d857422687068526d6477073ef83630ffcf0c1e.tar.gz
scooper-5d857422687068526d6477073ef83630ffcf0c1e.zip
Clean up page handlers
Diffstat (limited to '')
-rw-r--r--search.c42
1 files changed, 19 insertions, 23 deletions
diff --git a/search.c b/search.c
index 6fba589..3026a3b 100644
--- a/search.c
+++ b/search.c
@@ -39,10 +39,9 @@ const char *SearchQuery = SQL(
 	JOIN search ON search.rowid = events.event
 	WHERE coalesce(contexts.network = :network, true)
 		AND coalesce(contexts.name = :context, true)
-		AND coalesce(contexts.query = :query, true)
-		AND search MATCH :search
-	LIMIT :limit
-	OFFSET :offset;
+		AND contexts.query <= NOT :public
+		AND search MATCH :query
+	LIMIT :limit, :offset;
 );
 
 enum kcgi_err pageSearch(struct kreq *req) {
@@ -65,35 +64,32 @@ enum kcgi_err pageSearch(struct kreq *req) {
 		|| khtml_elem(&html, KELEM_TABLE);
 	if (error) return error;
 
-	dbBindText(stmt.search, ":highlight", "\26");
+	sqlite3_reset(stmt.search);
 	dbBindText(stmt.search, ":network", scope.network);
 	dbBindText(stmt.search, ":context", scope.context);
-	if (pagePublic) dbBindInt(stmt.search, ":query", false);
 	dbBindText(stmt.search, ":search", scope.query);
+	dbBindInt(stmt.search, ":public", pagePublic);
 	dbBindInt(stmt.search, ":limit", pageLimit);
 	dbBindInt(stmt.search, ":offset", offset);
+	dbBindText(stmt.search, ":highlight", "\26");
 
 	int result;
 	while (SQLITE_ROW == (result = sqlite3_step(stmt.search))) {
-		struct Event event = {
-			.event = sqlite3_column_int64(stmt.search, 0),
-			.time = sqlite3_column_int64(stmt.search, 1),
-			.network = (const char *)sqlite3_column_text(stmt.search, 2),
-			.context = (const char *)sqlite3_column_text(stmt.search, 3),
-			.type = sqlite3_column_int(stmt.search, 4),
-			.nick = (const char *)sqlite3_column_text(stmt.search, 5),
-			.user = (const char *)sqlite3_column_text(stmt.search, 6),
-			.host = (const char *)sqlite3_column_text(stmt.search, 7),
-			.target = (const char *)sqlite3_column_text(stmt.search, 8),
-			.message = (const char *)sqlite3_column_text(stmt.search, 9),
-		};
+		int i = 0;
+		struct Event event = {0};
+		event.event = sqlite3_column_int64(stmt.search, i++);
+		event.time = sqlite3_column_int64(stmt.search, i++);
+		event.network = sqlite3_column_text(stmt.search, i++);
+		event.context = sqlite3_column_text(stmt.search, i++);
+		event.type = sqlite3_column_int(stmt.search, i++);
+		event.nick = sqlite3_column_text(stmt.search, i++);
+		event.user = sqlite3_column_text(stmt.search, i++);
+		event.host = sqlite3_column_text(stmt.search, i++);
+		event.target = sqlite3_column_text(stmt.search, i++);
+		event.message = sqlite3_column_text(stmt.search, i++);
 		error = htmlEvent(&html, scope, event);
 		if (error) break;
 	}
 	if (result != SQLITE_DONE) errx(EX_SOFTWARE, "%s", sqlite3_errmsg(db));
-	sqlite3_reset(stmt.search);
-
-	return error
-		|| htmlFooter(&html)
-		|| khtml_close(&html);
+	return error || htmlFooter(&html) || khtml_close(&html);
 }