From 5df24ff1133b786b4c861b0cf745f52156d4d467 Mon Sep 17 00:00:00 2001 From: ner Date: Fri, 23 Oct 2026 21:12:46 +0300 Subject: [PATCH] fix(search): rank by votes-weighted rating so 1-vote outliers don't top results --- data/queries/search.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/data/queries/search.ts b/data/queries/search.ts index b87baf4..9ae1242 100644 --- a/data/queries/search.ts +++ b/data/queries/search.ts @@ -3,7 +3,14 @@ import mapMoviesSeriesResponseToShows from '../dto/Show'; export type SearchQueryProps = { query: string }; -const byRating = (a: Show, b: Show) => b.rating - a.rating || b.votes - a.votes || a.title.localeCompare(b.title); +// Votes-weighted (Bayesian) rating so a 10.0 with a single vote cannot outrank the actual match +const MIN_VOTES = 300; +const MEAN_RATING = 6; + +const weightedRating = (show: Show) => (show.votes * show.rating + MIN_VOTES * MEAN_RATING) / (show.votes + MIN_VOTES); + +const byRating = (a: Show, b: Show) => + weightedRating(b) - weightedRating(a) || b.votes - a.votes || a.title.localeCompare(b.title); const searchQuery = ({ query }: SearchQueryProps) => ({ queryKey: ['search', query],