Skip to content

Commit

Permalink
Update route.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
hezhijie0327 authored Dec 30, 2024
1 parent 36682af commit f6e0a35
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/app/api/search/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@ export async function POST(req: NextRequest) {

const searchResults = results.results
.sort((a: any, b: any) => {
const scoreDifference = b.score - a.score;
if (scoreDifference !== 0) return scoreDifference;

if (time_range) {
const dateA = new Date(a.publishedDate || 0).getTime();
const dateB = new Date(b.publishedDate || 0).getTime();
return dateB - dateA;
}
return b.score - a.score;

return 0;
})
.slice(0, max_results);
console.log('Search Results:', searchResults);
Expand Down

0 comments on commit f6e0a35

Please sign in to comment.