Recently I am doing a social networking project. In this project there is a option to get related products with given tags. Whenever I was doing the case study of this project i didn't give that much emphasize on the tag and related product. I thought about phew this is nothing. But at the time I involve myself to the database design I found oh my god what I thought about the tag word.
I just want to describe the problem here. In real time scenario I thought that I will pick each tag and search the product which also has the same tag. And after that i will count the maximum matched products. And show as related product. But after giving a few light over the problem I found a nice problem. I thought there could be a product with 32 or more then 32 tags. Even it could be 200. [Later I will decide it will be limited up to 32]. And if the ‘tag table’ consists fifty thousand records. Then I have to search full database 32 times or more than that. Then I have to calculate the whole result. If i think about n tags for a product then I have to query n+1 times. Just to show 2 or 3 related products.
I was thinking about reducing the query number. As my boss I was thinking about FULL TEXT Search. But I asked myself how delicious solve the same problem. They have much more data than I imagine. Later all credits goes to Google. I found few methods to solve the issue. But I am not even getting what are actually the databases experts want to say. I will discuss later how I solve this problem.
Here I attached some url where I got some ideas about Tag schema Design and queries.