diff options
| author | Mohamed Bassem <me@mbassem.com> | 2025-01-13 00:00:30 +0000 |
|---|---|---|
| committer | Mohamed Bassem <me@mbassem.com> | 2025-01-13 00:00:30 +0000 |
| commit | bbbf33536c6c1a73fdfe76c42ff19cd08aabcc6f (patch) | |
| tree | 7a3360c682da1908e60e5747063ca68719e026fe /packages/trpc/lib/search.ts | |
| parent | 38d403bcc26244e778a6e7a2f75ee39a9ec7ed27 (diff) | |
| download | karakeep-bbbf33536c6c1a73fdfe76c42ff19cd08aabcc6f.tar.zst | |
fix: Fix url matcher not matching sourceUrl. Fixes #874
Diffstat (limited to 'packages/trpc/lib/search.ts')
| -rw-r--r-- | packages/trpc/lib/search.ts | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/packages/trpc/lib/search.ts b/packages/trpc/lib/search.ts index eac323df..de76748b 100644 --- a/packages/trpc/lib/search.ts +++ b/packages/trpc/lib/search.ts @@ -4,6 +4,7 @@ import { exists, gt, gte, + isNotNull, like, lt, lte, @@ -13,6 +14,7 @@ import { } from "drizzle-orm"; import { + bookmarkAssets, bookmarkLinks, bookmarkLists, bookmarks, @@ -197,6 +199,20 @@ async function getIds( eq(bookmarks.userId, userId), comp(bookmarkLinks.url, `%${matcher.url}%`), ), + ) + .union( + db + .select({ id: bookmarkAssets.id }) + .from(bookmarkAssets) + .leftJoin(bookmarks, eq(bookmarks.id, bookmarkAssets.id)) + .where( + and( + eq(bookmarks.userId, userId), + // When a user is asking for a link, the inverse matcher should match only assets with URLs. + isNotNull(bookmarkAssets.sourceUrl), + comp(bookmarkAssets.sourceUrl, `%${matcher.url}%`), + ), + ), ); } case "favourited": { @@ -235,13 +251,16 @@ async function getIds( ); } case "type": { - const comp = matcher.inverse - ? ne(bookmarks.type, matcher.typeName) - : eq(bookmarks.type, matcher.typeName); + const comp = matcher.inverse ? ne : eq; return db .select({ id: bookmarks.id }) .from(bookmarks) - .where(and(eq(bookmarks.userId, userId), comp)); + .where( + and( + eq(bookmarks.userId, userId), + comp(bookmarks.type, matcher.typeName), + ), + ); } case "and": { const vals = await Promise.all( |
