diff options
| author | Mohamed Bassem <me@mbassem.com> | 2024-12-31 13:17:56 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-31 13:17:56 +0200 |
| commit | cbaf9e6034aa09911fca967b7af6cad11f154b3e (patch) | |
| tree | 6995d9d60d9ae5181af78e6577f8d7b724d7a971 /packages/trpc/routers/bookmarks.ts | |
| parent | f476fca758bb039f9605488b61ba35fc097d6cfc (diff) | |
| download | karakeep-cbaf9e6034aa09911fca967b7af6cad11f154b3e.tar.zst | |
feat: Introduce advanced search capabilities (#753)
* feat: Implement search filtering in the backend
* feat: Implement search language parser
* rename matcher name
* Add ability to interleve text
* More fixes
* be more tolerable to parsing errors
* Add a search query explainer widget
* Handle date parsing gracefully
* Fix the lockfile
* Encode query search param
* Fix table body error
* Fix error when writing quotes
Diffstat (limited to 'packages/trpc/routers/bookmarks.ts')
| -rw-r--r-- | packages/trpc/routers/bookmarks.ts | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/packages/trpc/routers/bookmarks.ts b/packages/trpc/routers/bookmarks.ts index 254ac6c2..3320b3b9 100644 --- a/packages/trpc/routers/bookmarks.ts +++ b/packages/trpc/routers/bookmarks.ts @@ -45,6 +45,7 @@ import { zNewBookmarkRequestSchema, zUpdateBookmarksRequestSchema, } from "@hoarder/shared/types/bookmarks"; +import { zMatcherSchema } from "@hoarder/shared/types/search"; import type { AuthedContext, Context } from "../index"; import { authedProcedure, router } from "../index"; @@ -54,6 +55,7 @@ import { mapDBAssetTypeToUserType, mapSchemaAssetTypeToDB, } from "../lib/attachments"; +import { getBookmarkIdsFromMatcher } from "../lib/search"; export const ensureBookmarkOwnership = experimental_trpcMiddleware<{ ctx: Context; @@ -521,6 +523,7 @@ export const bookmarksAppRouter = router({ .input( z.object({ text: z.string(), + matcher: zMatcherSchema.optional(), cursor: z .object({ offset: z.number(), @@ -548,8 +551,19 @@ export const bookmarksAppRouter = router({ message: "Search functionality is not configured", }); } + + let filter: string[]; + if (input.matcher) { + const bookmarkIds = await getBookmarkIdsFromMatcher(ctx, input.matcher); + filter = [ + `userId = '${ctx.user.id}' AND id IN [${bookmarkIds.join(",")}]`, + ]; + } else { + filter = [`userId = '${ctx.user.id}'`]; + } + const resp = await client.search(input.text, { - filter: [`userId = '${ctx.user.id}'`], + filter, showRankingScore: true, attributesToRetrieve: ["id"], sort: ["createdAt:desc"], |
