search for standard sites pub-search.waow.tech
search zig blog atproto
11
fork

Configure Feed

Select the types of activity you want to include in your feed.

use named params with zql.bind()

- DocsByTag, DocsByFtsAndTag, DocsByFts with :name params
- PubSearch with :query param
- cleaner: `.bind(.{ .query = fts_query, .tag = tag })`

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

zzstoatzz 1a172392 4f50725f

+43 -46
+1 -1
backend/build.zig.zon
··· 10 10 }, 11 11 .zql = .{ 12 12 .url = "https://github.com/zzstoatzz/zql/archive/main.tar.gz", 13 - .hash = "zql-0.0.1-alpha-xNRI4IYzAABlysQna0qdLkNqMwddTK9vrA0D8JKFjW11", 13 + .hash = "zql-0.0.1-alpha-xNRI4II5AAB3EZKhw1ER_m5yJLon0WgAJj_KANA2BwEl", 14 14 }, 15 15 }, 16 16 .paths = .{
+42 -45
backend/src/db/mod.zig
··· 90 90 } 91 91 92 92 // query types with comptime column extraction 93 - const DocQuery = zql.Query( 93 + const DocsByTag = zql.Query( 94 94 \\SELECT d.uri, d.did, d.title, '' as snippet, 95 95 \\ d.created_at, d.rkey, p.base_path, 96 96 \\ CASE WHEN d.publication_uri != '' THEN 1 ELSE 0 END as has_publication 97 97 \\FROM documents d 98 + \\LEFT JOIN publications p ON d.publication_uri = p.uri 99 + \\JOIN document_tags dt ON d.uri = dt.document_uri 100 + \\WHERE dt.tag = :tag 101 + \\ORDER BY d.created_at DESC LIMIT 40 102 + ); 103 + 104 + const DocsByFtsAndTag = zql.Query( 105 + \\SELECT f.uri, d.did, d.title, 106 + \\ snippet(documents_fts, 2, '<mark>', '</mark>', '...', 32) as snippet, 107 + \\ d.created_at, d.rkey, p.base_path, 108 + \\ CASE WHEN d.publication_uri != '' THEN 1 ELSE 0 END as has_publication 109 + \\FROM documents_fts f 110 + \\JOIN documents d ON f.uri = d.uri 111 + \\LEFT JOIN publications p ON d.publication_uri = p.uri 112 + \\JOIN document_tags dt ON d.uri = dt.document_uri 113 + \\WHERE documents_fts MATCH :query AND dt.tag = :tag 114 + \\ORDER BY rank LIMIT 40 115 + ); 116 + 117 + const DocsByFts = zql.Query( 118 + \\SELECT f.uri, d.did, d.title, 119 + \\ snippet(documents_fts, 2, '<mark>', '</mark>', '...', 32) as snippet, 120 + \\ d.created_at, d.rkey, p.base_path, 121 + \\ CASE WHEN d.publication_uri != '' THEN 1 ELSE 0 END as has_publication 122 + \\FROM documents_fts f 123 + \\JOIN documents d ON f.uri = d.uri 124 + \\LEFT JOIN publications p ON d.publication_uri = p.uri 125 + \\WHERE documents_fts MATCH :query 126 + \\ORDER BY rank LIMIT 40 98 127 ); 99 128 100 129 const Doc = struct { ··· 108 137 has_publication: bool, 109 138 }; 110 139 111 - const PubQuery = zql.Query( 140 + const PubSearch = zql.Query( 112 141 \\SELECT f.uri, p.did, p.name, 113 142 \\ snippet(publications_fts, 2, '<mark>', '</mark>', '...', 32) as snippet, 114 143 \\ p.rkey, p.base_path 115 144 \\FROM publications_fts f 145 + \\JOIN publications p ON f.uri = p.uri 146 + \\WHERE publications_fts MATCH :query 147 + \\ORDER BY rank LIMIT 10 116 148 ); 117 149 118 150 const Pub = struct { ··· 137 169 138 170 // search documents 139 171 var doc_result = if (query.len == 0 and tag_filter != null) 140 - c.query( 141 - \\SELECT d.uri, d.did, d.title, '' as snippet, 142 - \\ d.created_at, d.rkey, p.base_path, 143 - \\ CASE WHEN d.publication_uri != '' THEN 1 ELSE 0 END as has_publication 144 - \\FROM documents d 145 - \\LEFT JOIN publications p ON d.publication_uri = p.uri 146 - \\JOIN document_tags dt ON d.uri = dt.document_uri 147 - \\WHERE dt.tag = ? 148 - \\ORDER BY d.created_at DESC LIMIT 40 149 - , &.{tag_filter.?}) catch null 172 + c.query(DocsByTag.positional, DocsByTag.bind(.{ .tag = tag_filter.? })) catch null 150 173 else if (tag_filter) |tag| 151 - c.query( 152 - \\SELECT f.uri, d.did, d.title, 153 - \\ snippet(documents_fts, 2, '<mark>', '</mark>', '...', 32) as snippet, 154 - \\ d.created_at, d.rkey, p.base_path, 155 - \\ CASE WHEN d.publication_uri != '' THEN 1 ELSE 0 END as has_publication 156 - \\FROM documents_fts f 157 - \\JOIN documents d ON f.uri = d.uri 158 - \\LEFT JOIN publications p ON d.publication_uri = p.uri 159 - \\JOIN document_tags dt ON d.uri = dt.document_uri 160 - \\WHERE documents_fts MATCH ? AND dt.tag = ? 161 - \\ORDER BY rank LIMIT 40 162 - , &.{ fts_query, tag }) catch null 174 + c.query(DocsByFtsAndTag.positional, DocsByFtsAndTag.bind(.{ .query = fts_query, .tag = tag })) catch null 163 175 else 164 - c.query( 165 - \\SELECT f.uri, d.did, d.title, 166 - \\ snippet(documents_fts, 2, '<mark>', '</mark>', '...', 32) as snippet, 167 - \\ d.created_at, d.rkey, p.base_path, 168 - \\ CASE WHEN d.publication_uri != '' THEN 1 ELSE 0 END as has_publication 169 - \\FROM documents_fts f 170 - \\JOIN documents d ON f.uri = d.uri 171 - \\LEFT JOIN publications p ON d.publication_uri = p.uri 172 - \\WHERE documents_fts MATCH ? 173 - \\ORDER BY rank LIMIT 40 174 - , &.{fts_query}) catch null; 176 + c.query(DocsByFts.positional, DocsByFts.bind(.{ .query = fts_query })) catch null; 175 177 176 178 if (doc_result) |*res| { 177 179 defer res.deinit(); 178 180 for (res.rows) |row| { 179 - const doc = DocQuery.fromRow(Doc, row); 181 + const doc = DocsByFts.fromRow(Doc, row); 180 182 try jw.beginObject(); 181 183 try jw.objectField("type"); 182 184 try jw.write(if (doc.has_publication) "article" else "looseleaf"); ··· 201 203 // search publications (only if no tag filter) 202 204 if (tag_filter == null) { 203 205 var pub_result = c.query( 204 - \\SELECT f.uri, p.did, p.name, 205 - \\ snippet(publications_fts, 2, '<mark>', '</mark>', '...', 32) as snippet, 206 - \\ p.rkey, p.base_path 207 - \\FROM publications_fts f 208 - \\JOIN publications p ON f.uri = p.uri 209 - \\WHERE publications_fts MATCH ? 210 - \\ORDER BY rank LIMIT 10 211 - , &.{fts_query}) catch null; 206 + PubSearch.positional, 207 + PubSearch.bind(.{ .query = fts_query }), 208 + ) catch null; 212 209 213 210 if (pub_result) |*res| { 214 211 defer res.deinit(); 215 212 for (res.rows) |row| { 216 - const p = PubQuery.fromRow(Pub, row); 213 + const p = PubSearch.fromRow(Pub, row); 217 214 try jw.beginObject(); 218 215 try jw.objectField("type"); 219 216 try jw.write("publication");