diff options
| author | Mohamed Bassem <me@mbassem.com> | 2025-12-08 00:31:46 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-08 00:31:46 +0000 |
| commit | 1f43f232f723f6cb38864fe150ab78b1c0c62cd3 (patch) | |
| tree | ea9c6ed0e475f0f0f548290c8192ab1ffbded0f8 /packages/trpc | |
| parent | 13a090c4113efddc800b1f87a97e0244097bd4df (diff) | |
| download | karakeep-1f43f232f723f6cb38864fe150ab78b1c0c62cd3.tar.zst | |
feat: add is:broken search qualifier for broken links (#2225)
Add a new search qualifier `is:broken` that allows users to filter bookmarks
with broken or failed links. This matches the functionality on the broken links
settings page, where a link is considered broken if:
- crawlStatus is "failure"
- crawlStatusCode is less than 200
- crawlStatusCode is greater than 299
The qualifier supports negation with `-is:broken` to find working links.
Changes:
- Add brokenLinks matcher type definition
- Update search query parser to handle is:broken qualifier
- Implement query execution logic for broken links filtering
- Add autocomplete support with translations
- Add parser tests
- Update search query language documentation
Co-authored-by: Claude <noreply@anthropic.com>
Diffstat (limited to 'packages/trpc')
| -rw-r--r-- | packages/trpc/lib/search.ts | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/packages/trpc/lib/search.ts b/packages/trpc/lib/search.ts index 67348141..88f10f22 100644 --- a/packages/trpc/lib/search.ts +++ b/packages/trpc/lib/search.ts @@ -350,6 +350,29 @@ async function getIds( ), ); } + case "brokenLinks": { + // Only applies to bookmarks of type LINK + return db + .select({ id: bookmarkLinks.id }) + .from(bookmarkLinks) + .leftJoin(bookmarks, eq(bookmarks.id, bookmarkLinks.id)) + .where( + and( + eq(bookmarks.userId, userId), + matcher.brokenLinks + ? or( + eq(bookmarkLinks.crawlStatus, "failure"), + lt(bookmarkLinks.crawlStatusCode, 200), + gt(bookmarkLinks.crawlStatusCode, 299), + ) + : and( + eq(bookmarkLinks.crawlStatus, "success"), + gte(bookmarkLinks.crawlStatusCode, 200), + lte(bookmarkLinks.crawlStatusCode, 299), + ), + ), + ); + } case "and": { const vals = await Promise.all( matcher.matchers.map((m) => getIds(db, userId, m)), |
