From 9fdc8a9f3e4719e9eb9ec77cf2991e85eea43f1d Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Thu, 30 Jul 2026 18:26:15 +0500 Subject: [PATCH] core: fix lookup failing when searching notes with colors having same name --- packages/core/src/api/lookup.ts | 42 +++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/packages/core/src/api/lookup.ts b/packages/core/src/api/lookup.ts index ab7eaa620..3799ce2d5 100644 --- a/packages/core/src/api/lookup.ts +++ b/packages/core/src/api/lookup.ts @@ -156,8 +156,13 @@ export default class Lookup { : []; if ( - (!!tag?.length && tag.length !== tagIds.length) || - (!!color?.length && color.length !== colorIds.length) + !(await isMatchingAllColorsAndTags( + this.db, + colorIds, + tagIds, + colored ? [] : color || [], + tagged ? [] : tag || [] + )) ) return emptySearchResults(); @@ -1227,3 +1232,36 @@ function emptySearchResults() { () => Promise.resolve({ ids: [], items: [] }) ); } + +async function isMatchingAllColorsAndTags( + db: Database, + colorIds: string[], + tagIds: string[], + colors: string[], + tags: string[] +): Promise { + if (colors.length > 0) { + const resolvedColors = await db.colors.all + .fields(["colors.id", "colors.title"]) + .records(colorIds); + console.log({ resolvedColors }); + for (const [_, color] of Object.entries(resolvedColors)) { + console.log(color); + if (!color) return false; + if (colors.some((c) => c.toLowerCase() !== color.title.toLowerCase())) + return false; + } + } + + if (tags.length > 0) { + const resolvedTags = await db.tags.all + .fields(["tags.id", "tags.title"]) + .records(tagIds); + for (const [_, tag] of Object.entries(resolvedTags)) { + if (!tag) return false; + if (tags.some((c) => c.toLowerCase() !== tag.title.toLowerCase())) + return false; + } + } + return true; +}