So firstly here is the relevant table structure:
TUBE_VIDEOS
------
id
video_name
TAGS
----
id
tag_name
tag_type [either set to "actor" or "tag"]
TUBE_VIDEO_TAGS
----
tube_video_id
tag_id
I had asked a question a while back about how to use this data to get related videos: here — this solution basically took videos with the most common similar tags to decide which were most similar. Since then my database has been modified a bit to show what a tag is describing. So for example “Tom Cruise” is set to tag_type “actor” whereas “explosion” is set to tag_type “tag”. What I’d like to do is adjust the query to weigh actors heavier than tags. So essentially we would say to MySQL: Give me a list of video ID’s with the most matching actors, in the event of tie use the most matching tags next.
You can do that with just a lot of joins. The following query starts with the current video
tv. It looks for all tags belonging to that videotvt. Then it looks for all other video’s sharing one or more tagsrtvt. For the related video’s, it looks up the tag detailsrtand the video detailsrtv.After all the joins, you can count the various badge types and order by them.