diff --git a/packages/backend/src/server/api/endpoints/notes/search.ts b/packages/backend/src/server/api/endpoints/notes/search.ts index cc97e6f62..427119d5a 100644 --- a/packages/backend/src/server/api/endpoints/notes/search.ts +++ b/packages/backend/src/server/api/endpoints/notes/search.ts @@ -98,20 +98,16 @@ export default define(meta, paramDef, async (ps, me) => { if (ps.searchCwAndAlt) { query.andWhere( - new Brackets((qb) => { - qb.where("note.text &@~ :q", { q }) - .orWhere("note.cw &@~ :q", { q }) - .orWhere( - `EXISTS ( - SELECT FROM "drive_file" - WHERE - comment &@~ :q - AND - drive_file."id" = ANY(note."fileIds") - )`, - { q }, - ); - }), + `"note"."id" IN ( + SELECT "id" FROM "note" WHERE "note"."text" &@~ :q + UNION + SELECT "id" FROM "note" WHERE "note"."cw" &@~ :q + UNION + SELECT "note_file"."noteId" FROM "note_file" + INNER JOIN "drive_file" ON "drive_file"."id" = "note_file"."fileId" + WHERE "drive_file"."comment" &@~ :q + )`, + { q }, ); } else { query.andWhere("note.text &@~ :q", { q });