diff options
| author | Mohamed Bassem <me@mbassem.com> | 2025-01-04 14:39:38 +0000 |
|---|---|---|
| committer | Mohamed Bassem <me@mbassem.com> | 2025-01-04 14:39:38 +0000 |
| commit | ce16eda75f4d93646e485b7115398e81e7c88acc (patch) | |
| tree | a2e34e6067ce7b6818cd59bf8ce9fa52b8a9fc7c | |
| parent | 4439c91f426a8c8a13c4a84c8cb685ae67cc07e6 (diff) | |
| download | karakeep-ce16eda75f4d93646e485b7115398e81e7c88acc.tar.zst | |
fix: Change search endpoint to accept query as raw string
| -rw-r--r-- | apps/web/components/dashboard/search/SearchInput.tsx | 2 | ||||
| -rw-r--r-- | apps/web/lib/hooks/bookmark-search.ts | 5 | ||||
| -rw-r--r-- | packages/trpc/routers/bookmarks.ts | 12 |
3 files changed, 10 insertions, 9 deletions
diff --git a/apps/web/components/dashboard/search/SearchInput.tsx b/apps/web/components/dashboard/search/SearchInput.tsx index ace3d785..5e46fc18 100644 --- a/apps/web/components/dashboard/search/SearchInput.tsx +++ b/apps/web/components/dashboard/search/SearchInput.tsx @@ -84,7 +84,7 @@ const SearchInput = React.forwardRef< }} /> <QueryExplainerTooltip - className="-translate-1/2 absolute right-1.5 top-2 p-0.5" + className="-translate-1/2 absolute right-1.5 top-2 stroke-foreground p-0.5" parsedSearchQuery={parsedSearchQuery} /> {parsedSearchQuery.result === "full" && diff --git a/apps/web/lib/hooks/bookmark-search.ts b/apps/web/lib/hooks/bookmark-search.ts index 4662ffb6..386355f7 100644 --- a/apps/web/lib/hooks/bookmark-search.ts +++ b/apps/web/lib/hooks/bookmark-search.ts @@ -52,7 +52,7 @@ export function useDoBookmarkSearch() { } export function useBookmarkSearch() { - const { parsedSearchQuery } = useSearchQuery(); + const { searchQuery } = useSearchQuery(); const { data, @@ -64,8 +64,7 @@ export function useBookmarkSearch() { isFetchingNextPage, } = api.bookmarks.searchBookmarks.useInfiniteQuery( { - text: parsedSearchQuery.text, - matcher: parsedSearchQuery.matcher, + text: searchQuery, }, { placeholderData: keepPreviousData, diff --git a/packages/trpc/routers/bookmarks.ts b/packages/trpc/routers/bookmarks.ts index 47ba623b..f3884053 100644 --- a/packages/trpc/routers/bookmarks.ts +++ b/packages/trpc/routers/bookmarks.ts @@ -47,7 +47,6 @@ 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"; @@ -525,7 +524,6 @@ export const bookmarksAppRouter = router({ .input( z.object({ text: z.string(), - matcher: zMatcherSchema.optional(), cursor: z .object({ offset: z.number(), @@ -553,10 +551,14 @@ export const bookmarksAppRouter = router({ message: "Search functionality is not configured", }); } + const parsedQuery = parseSearchQuery(input.text); let filter: string[]; - if (input.matcher) { - const bookmarkIds = await getBookmarkIdsFromMatcher(ctx, input.matcher); + if (parsedQuery.matcher) { + const bookmarkIds = await getBookmarkIdsFromMatcher( + ctx, + parsedQuery.matcher, + ); filter = [ `userId = '${ctx.user.id}' AND id IN [${bookmarkIds.join(",")}]`, ]; @@ -564,7 +566,7 @@ export const bookmarksAppRouter = router({ filter = [`userId = '${ctx.user.id}'`]; } - const resp = await client.search(input.text, { + const resp = await client.search(parsedQuery.text, { filter, showRankingScore: true, attributesToRetrieve: ["id"], |
