[Feat] : 검색 결과 정확 일치 우선 정렬 (#184)#185
Conversation
|
/describe |
|
/review |
|
/improve |
Code Review by QodoNew Review StartedThis review has been superseded by a new analysisⓘ The new review experience is currently in Beta. Learn more |
1 similar comment
Code Review by QodoNew Review StartedThis review has been superseded by a new analysisⓘ The new review experience is currently in Beta. Learn more |
|
PR Description updated to latest commit (ee48ec6)
|
Review Summary by QodoPrioritize exact match results in search API with improved pagination
WalkthroughsDescription• Implement exact match priority sorting in search results • Separate exact and partial match queries with proper pagination • Extract helper functions for filter logic and query execution • Unify authenticated and unauthenticated search logic Diagramflowchart LR
A["Search Query"] --> B["Count Exact & Partial Matches"]
B --> C{Current Page Location}
C -->|Exact Only| D["Fetch Exact Results"]
C -->|Partial Only| E["Fetch Partial Results"]
C -->|Boundary| F["Fetch Exact + Partial"]
D --> G["Combine & Return"]
E --> G
F --> G
G --> H["Search Results"]
File Changes1. apps/web/src/app/api/search/route.ts
|
Code Review by Qodo
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| function applyExactFilter(baseQuery: any, type: string, searchText: string) { | ||
| if (type === 'all') { | ||
| return baseQuery.or(`title.ilike.${searchText},artist.ilike.${searchText}`); | ||
| } | ||
| return baseQuery.ilike(type, searchText); | ||
| } | ||
|
|
||
| function applyPartialFilter(baseQuery: any, type: string, searchText: string) { | ||
| if (type === 'all') { | ||
| return baseQuery | ||
| .or(`title.ilike.%${searchText}%,artist.ilike.%${searchText}%`) | ||
| .not('title', 'ilike', searchText) | ||
| .not('artist', 'ilike', searchText); |
There was a problem hiding this comment.
1. Or filter string injection 🐞 Bug ⛨ Security
applyExactFilter/applyPartialFilter interpolate the user-provided query directly into the .or() filter string for type=all, so inputs containing PostgREST-delimiter characters (e.g., ,, (, )) can break the filter syntax or alter the filter logic. This can cause incorrect search results or request failures (500) for certain queries.
Agent Prompt
### Issue description
For `type=all`, the code constructs PostgREST filter strings with raw user input and passes them to `.or(...)`. This can break parsing or let the user affect the filter expression.
### Issue Context
`q` comes from the request URL and is forwarded by the web client without escaping.
### Fix Focus Areas
- apps/web/src/app/api/search/route.ts[25-40]
- apps/web/src/app/api/search/route.ts[131-168]
### Suggested fix
- Avoid building `.or()` filter strings with raw input. Prefer a server-side RPC (SQL function) that accepts `query` as a parameter and applies `(title ILIKE ...) OR (artist ILIKE ...)` safely.
- If RPC is not an option, implement a strict escaping/validation layer for `q` specifically for PostgREST filter-string contexts (reject or escape `,()`).
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
User description
📌 PR 제목
[Feat] : 검색 결과 정확 일치 우선 정렬
📌 변경 사항
type=all(제목+가수),type=title,type=artist모든 검색 타입 지원executeSearchQueries함수로 통합applyExactFilter,applyPartialFilter헬퍼 함수 추출로 가독성 개선💬 추가 참고 사항
PR Type
Enhancement
Description
Implement exact match priority sorting in search results
Separate exact and partial match queries for better ranking
Handle pagination across exact-partial match boundaries
Consolidate duplicate search logic for authenticated/unauthenticated users
Extract helper functions for improved code readability
Diagram Walkthrough
File Walkthrough
route.ts
Refactor search API with exact match priority logicapps/web/src/app/api/search/route.ts
applyExactFilterhelper function for exact match queriesapplyPartialFilterhelper function for partial match queriesexcluding exact matches
executeSearchQueriesfunction to consolidate search logic withexact-match priority
and partial results
single flow
state