aboutsummaryrefslogtreecommitdiffstats
path: root/packages/trpc/routers
diff options
context:
space:
mode:
Diffstat (limited to 'packages/trpc/routers')
-rw-r--r--packages/trpc/routers/bookmarks.ts16
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"],