Skip to content

Commit c6f563f

Browse files
authored
Update route.ts
1 parent f6e0a35 commit c6f563f

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/app/api/search/route.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,11 @@ export async function POST(req: NextRequest) {
5555
const results = await response.json();
5656

5757
const searchResults = results.results
58-
.sort((a: any, b: any) => {
59-
const scoreDifference = b.score - a.score;
60-
if (scoreDifference !== 0) return scoreDifference;
61-
62-
if (time_range) {
63-
const dateA = new Date(a.publishedDate || 0).getTime();
64-
const dateB = new Date(b.publishedDate || 0).getTime();
65-
return dateB - dateA;
66-
}
67-
68-
return 0;
69-
})
58+
.sort((a: any, b: any) =>
59+
b.score !== a.score
60+
? b.score - a.score
61+
: new Date(b.publishedDate || 0).getTime() - new Date(a.publishedDate || 0).getTime()
62+
)
7063
.slice(0, max_results);
7164
console.log('Search Results:', searchResults);
7265

0 commit comments

Comments
 (0)