Skip to content

Commit

Permalink
fix(tag-case-sensitive): update tags query to make it case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
rockingrohit9639 committed Dec 12, 2024
1 parent 42745e2 commit b84eeaa
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions app/modules/asset/query.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,26 +767,26 @@ function addArrayFilter(whereClause: Prisma.Sql, filter: Filter): Prisma.Sql {
*/
switch (filter.operator) {
case "contains": {
// Single tag filtering using the existing join
return Prisma.sql`${whereClause} AND t.name ILIKE ${`%${filter.value}%`}`;
// Single tag filtering using the existing join with case-insensitive comparison
return Prisma.sql`${whereClause} AND LOWER(t.name) = LOWER(${filter.value})`;
}
case "containsAll": {
// ALL tags must be present
// ALL tags must be present, case-insensitive
const values = (filter.value as string).split(",").map((v) => v.trim());
return Prisma.sql`${whereClause} AND NOT EXISTS (
SELECT unnest(${values}::text[]) AS required_tag
SELECT LOWER(unnest(${values}::text[])) AS required_tag
EXCEPT
SELECT t.name
SELECT LOWER(t2.name)
FROM "_AssetToTag" att2
JOIN "Tag" t2 ON t2.id = att2."B"
WHERE att2."A" = a.id
)`;
}
case "containsAny": {
// ANY of the tags must be present
// ANY of the tags must be present, case-insensitive
const values = (filter.value as string).split(",").map((v) => v.trim());
const valuesArray = `{${values.map((v) => `"${v}"`).join(",")}}`;
return Prisma.sql`${whereClause} AND t.name = ANY(${valuesArray}::text[])`;
return Prisma.sql`${whereClause} AND LOWER(t.name) = ANY(ARRAY(SELECT LOWER(unnest(${valuesArray}::text[]))))`;
}
default:
return whereClause;
Expand Down

0 comments on commit b84eeaa

Please sign in to comment.