I'm building a MySQL tagging DB to allow users to tag products.
My current design uses these tables:
Account
id (PK)
username
Product
id (PK)
product_name
Product_Tag
id (PK)
product_id (FK to Product)
tag_id (FK to Tag)
account_id (FK to Account)
created_date
Tag
id (PK)
tag_name
Note in my design, I'm tracking which user tagged the product and when, and enabling a product to be tagged multiple times using the same tag so I know which tags are most popular for a given product.
I'm trying to figure out a tag search query that returns products most tagged to the searched tags. For example, if I query "red dress", products that are more heavily tagged with "red" and "dress" should appear towards the top in the result set. What query can accomplish this with my existing design?