From a92ada7727b2596414aafe204e5001eb066569cb Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sat, 13 Sep 2025 21:37:56 +0100 Subject: feat(search): add title search qualifier (#1940) * fix(search): include link titles in title matcher * docs(search): add title qualifier * docs: remove title qualifier from v0.27 guide --- packages/trpc/lib/search.ts | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'packages/trpc/lib/search.ts') diff --git a/packages/trpc/lib/search.ts b/packages/trpc/lib/search.ts index d4130798..67348141 100644 --- a/packages/trpc/lib/search.ts +++ b/packages/trpc/lib/search.ts @@ -5,12 +5,14 @@ import { gt, gte, isNotNull, + isNull, like, lt, lte, ne, notExists, notLike, + or, } from "drizzle-orm"; import { @@ -245,6 +247,50 @@ async function getIds( ), ); } + case "title": { + const comp = matcher.inverse ? notLike : like; + if (matcher.inverse) { + return db + .select({ id: bookmarks.id }) + .from(bookmarks) + .leftJoin(bookmarkLinks, eq(bookmarks.id, bookmarkLinks.id)) + .where( + and( + eq(bookmarks.userId, userId), + or( + isNull(bookmarks.title), + comp(bookmarks.title, `%${matcher.title}%`), + ), + or( + isNull(bookmarkLinks.title), + comp(bookmarkLinks.title, `%${matcher.title}%`), + ), + ), + ); + } + + return db + .select({ id: bookmarks.id }) + .from(bookmarks) + .where( + and( + eq(bookmarks.userId, userId), + comp(bookmarks.title, `%${matcher.title}%`), + ), + ) + .union( + db + .select({ id: bookmarkLinks.id }) + .from(bookmarkLinks) + .leftJoin(bookmarks, eq(bookmarks.id, bookmarkLinks.id)) + .where( + and( + eq(bookmarks.userId, userId), + comp(bookmarkLinks.title, `%${matcher.title}%`), + ), + ), + ); + } case "favourited": { return db .select({ id: bookmarks.id }) -- cgit v1.2.3-70-g09d2