Skip to content

Commit

Permalink
fix: Change search endpoint to accept query as raw string
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedBassem committed Jan 4, 2025
1 parent 4439c91 commit ce16eda
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion apps/web/components/dashboard/search/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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" &&
Expand Down
5 changes: 2 additions & 3 deletions apps/web/lib/hooks/bookmark-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function useDoBookmarkSearch() {
}

export function useBookmarkSearch() {
const { parsedSearchQuery } = useSearchQuery();
const { searchQuery } = useSearchQuery();

const {
data,
Expand All @@ -64,8 +64,7 @@ export function useBookmarkSearch() {
isFetchingNextPage,
} = api.bookmarks.searchBookmarks.useInfiniteQuery(
{
text: parsedSearchQuery.text,
matcher: parsedSearchQuery.matcher,
text: searchQuery,
},
{
placeholderData: keepPreviousData,
Expand Down
12 changes: 7 additions & 5 deletions packages/trpc/routers/bookmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -525,7 +524,6 @@ export const bookmarksAppRouter = router({
.input(
z.object({
text: z.string(),
matcher: zMatcherSchema.optional(),
cursor: z
.object({
offset: z.number(),
Expand Down Expand Up @@ -553,18 +551,22 @@ 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(",")}]`,
];
} else {
filter = [`userId = '${ctx.user.id}'`];
}

const resp = await client.search(input.text, {
const resp = await client.search(parsedQuery.text, {
filter,
showRankingScore: true,
attributesToRetrieve: ["id"],
Expand Down

0 comments on commit ce16eda

Please sign in to comment.