I have a theme gallery system. I need to implement a ‘related themes’ item inside the theme preview page.
Each theme has colors and tags, so between 5 tables i have:
-
theme
- id_theme
- title
-
color
- id_color
- title (red)
-
tag
- id_tag
- title (planets)
-
theme_color
- id_theme
- id_color
-
theme_tag
- id_theme
- id_tag
The catch, is that I only have to receive 5 results, and they must show the ones that have more matches between colors and tags. With that requirement, I have no idea on where to start. Any ideas?
If you want the five themes that have the most items in common with a given theme, you might try something like:
Not tested, buyer beware, but I hope you get the idea. This creates a row for every color or tag that matches a color or tag assigned to the @target_id_theme, orders them by count descending, and gives you the top 5.