core: fix lookup failing when searching notes with colors having same name

This commit is contained in:
Abdullah Atta
2026-07-30 18:26:15 +05:00
parent 92a04e2aa7
commit 9fdc8a9f3e

View File

@@ -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<boolean> {
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;
}