Scnerio:
https://www.funtraker.com lists movies, TV shows and games. On the display page of each resource (Movie, Tv Show, etc.), we want to list related resources.
Scheme:
class Movie < AR::Base has_many :resource_genres, as: :resource has_many :genres, through: :resource_genres end class ResourceGenre belongs_to :resource, polymorphic: true end
Now I want to get a list of related films based on the matching genre (two films are related if both have a comedy genre). And these related films need to be ordered by the maximum number of agreed genres.
Well here are examples of films and the expected result.
#Input Movie Genres Movie 1: horror, comedy, action, war Movie 2: action, thriller, crime, animation Movie 3: comedy, war, action, thriller Movie 4: crime, animation, action, war
I hope the question will make sense.
UPDATE: SQL-only solution search. I do not need to cache the results in any other table.
source share