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.

fix: tag + platform filter now works correctly

added queries for all filter combinations:
- DocsByTagAndPlatform (tag + platform, no query)
- DocsByFtsAndTagAndPlatform (query + tag + platform)
- DocsByPlatform (platform only, no query)

previously, tag filter took priority and platform was ignored.

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

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

zzstoatzz cf495f4b fc902b3e

+62 -7
+62 -7
backend/src/search.zig
··· 119 119 \\ORDER BY rank LIMIT 40 120 120 ); 121 121 122 + const DocsByTagAndPlatform = zql.Query( 123 + \\SELECT d.uri, d.did, d.title, '' as snippet, 124 + \\ d.created_at, d.rkey, 125 + \\ COALESCE(p.base_path, (SELECT base_path FROM publications WHERE did = d.did LIMIT 1), '') as base_path, 126 + \\ CASE WHEN d.publication_uri != '' THEN 1 ELSE 0 END as has_publication, 127 + \\ d.platform, COALESCE(d.path, '') as path 128 + \\FROM documents d 129 + \\LEFT JOIN publications p ON d.publication_uri = p.uri 130 + \\JOIN document_tags dt ON d.uri = dt.document_uri 131 + \\WHERE dt.tag = :tag AND d.platform = :platform 132 + \\ORDER BY d.created_at DESC LIMIT 40 133 + ); 134 + 135 + const DocsByFtsAndTagAndPlatform = zql.Query( 136 + \\SELECT f.uri, d.did, d.title, 137 + \\ snippet(documents_fts, 2, '', '', '...', 32) as snippet, 138 + \\ d.created_at, d.rkey, 139 + \\ COALESCE(p.base_path, (SELECT base_path FROM publications WHERE did = d.did LIMIT 1), '') as base_path, 140 + \\ CASE WHEN d.publication_uri != '' THEN 1 ELSE 0 END as has_publication, 141 + \\ d.platform, COALESCE(d.path, '') as path 142 + \\FROM documents_fts f 143 + \\JOIN documents d ON f.uri = d.uri 144 + \\LEFT JOIN publications p ON d.publication_uri = p.uri 145 + \\JOIN document_tags dt ON d.uri = dt.document_uri 146 + \\WHERE documents_fts MATCH :query AND dt.tag = :tag AND d.platform = :platform 147 + \\ORDER BY rank LIMIT 40 148 + ); 149 + 150 + const DocsByPlatform = zql.Query( 151 + \\SELECT d.uri, d.did, d.title, '' as snippet, 152 + \\ d.created_at, d.rkey, 153 + \\ COALESCE(p.base_path, (SELECT base_path FROM publications WHERE did = d.did LIMIT 1), '') as base_path, 154 + \\ CASE WHEN d.publication_uri != '' THEN 1 ELSE 0 END as has_publication, 155 + \\ d.platform, COALESCE(d.path, '') as path 156 + \\FROM documents d 157 + \\LEFT JOIN publications p ON d.publication_uri = p.uri 158 + \\WHERE d.platform = :platform 159 + \\ORDER BY d.created_at DESC LIMIT 40 160 + ); 161 + 122 162 /// Publication search result (internal) 123 163 const Pub = struct { 124 164 uri: []const u8, ··· 175 215 try jw.beginArray(); 176 216 177 217 const fts_query = try buildFtsQuery(alloc, query); 218 + const has_query = query.len > 0; 219 + const has_tag = tag_filter != null; 220 + const has_platform = platform_filter != null; 178 221 179 - // search documents 180 - var doc_result = if (query.len == 0 and tag_filter != null) 222 + // search documents - handle all filter combinations 223 + var doc_result = if (has_query and has_tag and has_platform) 224 + c.query(DocsByFtsAndTagAndPlatform.positional, DocsByFtsAndTagAndPlatform.bind(.{ 225 + .query = fts_query, 226 + .tag = tag_filter.?, 227 + .platform = platform_filter.?, 228 + })) catch null 229 + else if (has_query and has_tag) 230 + c.query(DocsByFtsAndTag.positional, DocsByFtsAndTag.bind(.{ .query = fts_query, .tag = tag_filter.? })) catch null 231 + else if (has_query and has_platform) 232 + c.query(DocsByFtsAndPlatform.positional, DocsByFtsAndPlatform.bind(.{ .query = fts_query, .platform = platform_filter.? })) catch null 233 + else if (has_query) 234 + c.query(DocsByFts.positional, DocsByFts.bind(.{ .query = fts_query })) catch null 235 + else if (has_tag and has_platform) 236 + c.query(DocsByTagAndPlatform.positional, DocsByTagAndPlatform.bind(.{ .tag = tag_filter.?, .platform = platform_filter.? })) catch null 237 + else if (has_tag) 181 238 c.query(DocsByTag.positional, DocsByTag.bind(.{ .tag = tag_filter.? })) catch null 182 - else if (tag_filter) |tag| 183 - c.query(DocsByFtsAndTag.positional, DocsByFtsAndTag.bind(.{ .query = fts_query, .tag = tag })) catch null 184 - else if (platform_filter) |pf| 185 - c.query(DocsByFtsAndPlatform.positional, DocsByFtsAndPlatform.bind(.{ .query = fts_query, .platform = pf })) catch null 239 + else if (has_platform) 240 + c.query(DocsByPlatform.positional, DocsByPlatform.bind(.{ .platform = platform_filter.? })) catch null 186 241 else 187 - c.query(DocsByFts.positional, DocsByFts.bind(.{ .query = fts_query })) catch null; 242 + null; // no filters at all - return empty 188 243 189 244 if (doc_result) |*res| { 190 245 defer res.deinit();