This commit is contained in:
2026-06-13 13:40:15 +03:30
parent 33a23962c8
commit 57ca732917
+7 -3
View File
@@ -482,10 +482,14 @@ private function similarMedia(Media $media, int $limit = 5)
'tags as tag_matches' => fn ($t) => $t->whereIn('tags.id', $tagIds ?: [0]), 'tags as tag_matches' => fn ($t) => $t->whereIn('tags.id', $tagIds ?: [0]),
]) ])
->with(['image', 'detailImage', 'categories', 'subCategories', 'tags']) ->with(['image', 'detailImage', 'categories', 'subCategories', 'tags'])
->orderByRaw('(category_matches + subcategory_matches + tag_matches) desc') // Pull a recent candidate pool (portable; Postgres can't ORDER BY alias
// expressions), then rank by overlap in PHP.
->orderByDesc('created_at') ->orderByDesc('created_at')
->limit($limit) ->limit(60)
->get(); ->get()
->sortByDesc(fn ($m) => $m->category_matches + $m->subcategory_matches + $m->tag_matches)
->take($limit)
->values();
} }
public function rate(Request $request, $mediaId) public function rate(Request $request, $mediaId)