I have a database with primarily 3 tables, (ImageID, imageName), ( ImageID | Tags ) and (tagID, tagName)
So each image can have many tags associated to it. How would I efficiently and scale able select 1 image and find the next x images that are most similar ( have the same tags associated to it)
All done on the web using javascript, ajax and php. Thanks for any suggestions and hints on how to approach this!
Edit:
Yes Mysql
The format was ( Table ) and ( ROW | ROW )
IMAGEID, TAGID are primary keys
So yes there is a normalized index of IMAGEIDS and TAGIDS to save room.
I am trying to get if image A has 10 of 10 tags in common with image B it would be returned higher then IMAGE C which has 6 of 10 tags in common.
Sorry for being ambiguous.I am developing the site, so i can add keys, foreign keys, etc if its impossible to do it with what i have. And it doesnt have to be done in one giant SQL statement, i just dont want to get into a o(n^2) situation by comparing my first row to every other row 1 at a time.
Unfortunately this design isn’t actually very scalable. Simply because you really will be comparing the tags of one image against the tags of pretty much every other image.
It’s codable, it’s just not overly scalable. (100’s of images? Great! Tens of thousands? You’ll be able to measure the lookup speed.)
Then use LIMIT or TOP (depending on your flavour of SQL) to pick only the first (N) images.
NOTE: This assumes you don’t have all the tags for an image in a string held in one field of one row. If you do, you really should normalise the data to have one
(ImageID,TagID)per row,