fix(search): rank by votes-weighted rating so 1-vote outliers don't top results
This commit is contained in:
1 parent
6cff846f94
commit
5df24ff113
1 file changed
+8
-1
@@ -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],
|
||||
|
||||
Reference in new issue
Block a user