feat: Enhance package search with normalized name matching and remove sync:arch script.

This commit is contained in:
Yusuf İpek
2025-11-22 16:10:15 +03:00
parent afd4456893
commit 00f3ce4706
2 changed files with 9 additions and 5 deletions
+1 -2
View File
@@ -10,8 +10,7 @@
"type-check": "tsc --noEmit", "type-check": "tsc --noEmit",
"test:db": "node scripts/test-db.js", "test:db": "node scripts/test-db.js",
"init:backend": "chmod +x scripts/init-backend.sh && ./scripts/init-backend.sh", "init:backend": "chmod +x scripts/init-backend.sh && ./scripts/init-backend.sh",
"init:db": "node scripts/init-db.js", "init:db": "node scripts/init-db.js"
"sync:arch": "npx tsx scripts/sync-arch.ts"
}, },
"dependencies": { "dependencies": {
"@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4",
+7 -2
View File
@@ -44,7 +44,9 @@ export class PackageService {
if (search) { if (search) {
whereConditions.push(`( whereConditions.push(`(
p.name ILIKE $${paramIndex} OR p.name ILIKE $${paramIndex} OR
p.description ILIKE $${paramIndex} p.description ILIKE $${paramIndex} OR
REPLACE(p.name, '-', ' ') ILIKE $${paramIndex} OR
REPLACE(p.name, '-', '') ILIKE $${paramIndex}
)`) )`)
values.push(`%${search}%`) values.push(`%${search}%`)
paramIndex++ paramIndex++
@@ -69,7 +71,8 @@ export class PackageService {
// 1. Exact name match // 1. Exact name match
// 2. Name starts with search term // 2. Name starts with search term
// 3. Name contains search term // 3. Name contains search term
// 4. Description contains search term // 4. Normalized name matches (hyphens -> spaces, or stripped)
// 5. Description contains search term
// Then sort by popularity/name as tie-breaker // Then sort by popularity/name as tie-breaker
orderClause = ` orderClause = `
ORDER BY ORDER BY
@@ -77,6 +80,8 @@ export class PackageService {
WHEN p.name ILIKE $${paramIndex} THEN 0 -- Exact match WHEN p.name ILIKE $${paramIndex} THEN 0 -- Exact match
WHEN p.name ILIKE $${paramIndex + 1} THEN 1 -- Starts with WHEN p.name ILIKE $${paramIndex + 1} THEN 1 -- Starts with
WHEN p.name ILIKE $${paramIndex + 2} THEN 2 -- Contains in name WHEN p.name ILIKE $${paramIndex + 2} THEN 2 -- Contains in name
WHEN REPLACE(p.name, '-', ' ') ILIKE $${paramIndex + 2} THEN 2 -- Normalized (space)
WHEN REPLACE(p.name, '-', '') ILIKE $${paramIndex + 2} THEN 2 -- Normalized (strip)
ELSE 3 -- Contains in description only ELSE 3 -- Contains in description only
END ASC, END ASC,
p.popularity_score DESC, p.popularity_score DESC,