Skip to content

Commit a50b54b

Browse files
committed
[enhancement 🔥] case insensitive skills search
1 parent 25bc781 commit a50b54b

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/components/contents/ProfileGrid.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ const ProfileGrid = async ({ page, searchParams }: Props) => {
2323
const currentPage = parseInt(page); // like 1
2424
const itemPerPage = 5; // we want to show 5 item in per pages
2525
const offset = (currentPage - 1) * itemPerPage; // (1 - 1) * 3 = 0
26-
const searchSkills = searchParams ? searchParams.split(/[\s,]+/) : []; // regular expression to accept inputs separated by comma, space or both
26+
const searchSkills = searchParams ? searchParams.toLowerCase().split(/[\s,]+/) : []; // regular expression to accept inputs separated by comma, space or both
2727

2828
// In order to get rid of the "error: operator does not exist: json @> json" I mannually cast the skills column to JSONB
29-
const skillsCondition = searchSkills.length > 0
30-
? sql.raw(`"skills"::JSONB @> '${JSON.stringify(searchSkills)}'::JSONB`)
31-
: undefined;
29+
const skillsCondition = searchSkills.length > 0
30+
? sql.raw(`lower("skills"::text)::JSONB @> '${JSON.stringify(searchSkills.map(skill => skill.toLowerCase()))}'::JSONB`)
31+
: undefined;
3232

3333
const [lengths, profiles] = await Promise.all([
3434
db.select({ count: sql<number>`count(*)` }).from(users),

0 commit comments

Comments
 (0)