Skip to content

Commit 58525d3

Browse files
authored
Merge pull request #32 from werther41/topic-ranking-calculation-adjustment
Refactor scoring calculations to use logarithmic scaling
2 parents ff9978e + f0a7e81 commit 58525d3

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

app/api/topics/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export async function GET(request: NextRequest) {
9191
combinedScore:
9292
"combinedScore" in topic
9393
? topic.combinedScore
94-
: topic.occurrence_count * topic.avg_tfidf_score,
94+
: Math.log(topic.occurrence_count + 1) * topic.avg_tfidf_score,
9595
})),
9696
metadata: {
9797
timeWindow,

lib/topic-extraction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ export async function getTrendingTopics(options?: {
319319
}
320320

321321
query += `
322-
ORDER BY (occurrence_count * avg_tfidf_score) DESC
322+
ORDER BY (LOG(occurrence_count + 1) * avg_tfidf_score) DESC
323323
LIMIT ?
324324
`
325325
params.push(limit)

lib/topic-search.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ export async function getDiverseTopics(options?: {
270270
params.push(limit * 3) // Get more for randomization
271271
} else {
272272
query += `
273-
ORDER BY (occurrence_count * avg_tfidf_score) DESC
273+
ORDER BY (LOG(occurrence_count + 1) * avg_tfidf_score) DESC
274274
LIMIT ?
275275
`
276276
params.push(limit * 2) // Get more to filter for diversity
@@ -287,7 +287,7 @@ export async function getDiverseTopics(options?: {
287287
occurrenceCount,
288288
avgTfidfScore,
289289
lastSeenAt: row.last_seen_at as string,
290-
combinedScore: occurrenceCount * avgTfidfScore,
290+
combinedScore: Math.log(occurrenceCount + 1) * avgTfidfScore,
291291
}
292292
})
293293

0 commit comments

Comments
 (0)