From bbbf33536c6c1a73fdfe76c42ff19cd08aabcc6f Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Mon, 13 Jan 2025 00:00:30 +0000 Subject: fix: Fix url matcher not matching sourceUrl. Fixes #874 --- packages/trpc/lib/search.ts | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'packages/trpc/lib/search.ts') 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( -- cgit v1.2.3-70-g09d2