From d7c095fdb7ce98e48009ce513f2c0e1cbd15a7a1 Mon Sep 17 00:00:00 2001 From: valknarness Date: Wed, 29 Oct 2025 06:52:08 +0100 Subject: [PATCH] fix: search API FTS join and error handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed 500 Internal Server Error in search API by correcting the FTS5 full-text search query join. The previous query incorrectly joined fts.rowid directly to repositories.id, but FTS rowid corresponds to the readmes table. Now properly joins through readmes table first. Also enhanced error logging with detailed error messages in development mode for easier debugging. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/api/search/route.ts | 8 +++++++- lib/db.ts | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/api/search/route.ts b/app/api/search/route.ts index b981c16..b9a63ea 100644 --- a/app/api/search/route.ts +++ b/app/api/search/route.ts @@ -40,8 +40,14 @@ export async function GET(request: NextRequest) { return NextResponse.json(results) } catch (error) { console.error('Search API error:', error) + const errorMessage = error instanceof Error ? error.message : 'Unknown error' + console.error('Error details:', errorMessage) + return NextResponse.json( - { error: 'Internal server error' }, + { + error: 'Internal server error', + ...(process.env.NODE_ENV === 'development' && { details: errorMessage }) + }, { status: 500 } ) } diff --git a/lib/db.ts b/lib/db.ts index 7c113d6..ee12080 100644 --- a/lib/db.ts +++ b/lib/db.ts @@ -128,7 +128,8 @@ export function searchRepositories(options: SearchOptions): PaginatedResults', '', '...', 32) as snippet FROM readmes_fts fts - JOIN repositories r ON fts.rowid = r.id + JOIN readmes rm ON fts.rowid = rm.rowid + JOIN repositories r ON rm.repository_id = r.id LEFT JOIN awesome_lists al ON r.awesome_list_id = al.id WHERE readmes_fts MATCH ? `