Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an agreed ideal schema for tagging

I have a photo website and i want to support tags as my original category bucketing is starting to fail (some pictures are family and vacations, or school and friends). Is there an agreed tagging db schema?

I still want to support having photos as part of an album.

Right now i have a few tables:

Photos

  • PhotoID
  • PhotoAlbumID
  • Caption
  • Date

Photo Album

  • AlbumID
  • AlbumName
  • AlbumDate
like image 431
leora Avatar asked Oct 05 '08 20:10

leora


People also ask

What is a tag schema?

The Tag Schema Common Service is an IBM Multicloud Management Platform (MCMP) feature that allows you to set policies governing the use of tags in MCMP to help you organize your reports and monitor and enforce compliance. The tag schema service supports both MCMP internal and external (provider side) tags.

What are the 3 types of schema in the database?

Schema is of three types: Logical Schema, Physical Schema and view Schema. Logical Schema – It describes the database designed at logical level. Physical Schema – It describes the database designed at physical level. View Schema – It defines the design of the database at the view level.

What is the goal of schema design?

The goals of good database schema design include: Reducing or eliminating data redundancy. Preventing data inconsistencies and inaccuracies. Ensuring the correctness and integrity of your data.

Why is data tagging important?

Data tagging allows users to organize information more efficiently by associating pieces of information (websites or photos, for example) with tags, or keywords.


4 Answers

There are various schemas which are effective, each with their own performance implications for the common queries you'll need as the number of tagged items grows:

  • http://howto.philippkeller.com/2005/04/24/Tags-Database-schemas/
  • http://howto.philippkeller.com/2005/06/19/Tagsystems-performance-tests/

Personally, I like having a tag table and a link table which associates tags with items, as it's denormalized (no duplication of tag names) and I can store additional information in the link table (such as when the item was tagged) when necessary.

You can also add some denormalised data if you're feeling frisky and want simple selects at the cost of the additional data maintenance required by storing usage counts in the tag table, or storing tag names which were used in the item table itself to avoid hitting the link table and tag table for each item, which is useful for displaying multiple items with all their tags and for simple tag versioning... if you're into that sort of thing ;)

like image 121
Jonny Buchanan Avatar answered Sep 23 '22 12:09

Jonny Buchanan


I've done this in a small system without very many users, but I've wondered before if there was an "accepted" way to manage tags. After reading through the links posted by insin and plenty of other blog posts on tagging, it seems that the accepted way is to store it fully normalized and cache certain things if your data set gets too big.

Since it's a many-many relationship (each tag can belong to any number of photos - each photo can have many tags), relational database theory has you create a photo table, a tag table and a cross-reference table to link them.

photos
  photoid
  caption
  filename
  date

tags
  tagid
  tagname

phototags
  photoid
  tagid

This has scaling problems selecting from really large datasets, but so do all the less-normalized schemas (sorting and filtering by a text field will probably always be slower than using an integer, for example). If you grow as large as delicious or maybe even StackOverflow you'll probably have to do some caching of your tag sets.

Another issue you'll have to face is the issue of tag normalization. This doesn't have anything to do with database normalization - it's just making sure that (for example) the "StackOverflow", "stackoverflow" and "stack overflow" tags are the same. Lots of places disallow whitespace or automatically strip it out. Sometimes you'll see the same thing for punctuation - making "StackOverflow" the same as "Stack-Overflow". Auto-lowercasing is pretty standard. You'll even see special case normalization - like making "c#" the same as "csharp".

Happy tagging!

like image 24
Neall Avatar answered Sep 21 '22 12:09

Neall


Something like this comes to my mind: add those two tables

Tags

  • TagID
  • TagName
  • TagDescription

PhotoTags

  • PhotoID
  • TagID

You can extend this to albums too, having an intersection table between Photo Albums and Tags.

like image 40
friol Avatar answered Sep 21 '22 12:09

friol


I suggest looking to see how established open-source software does it. For example, Gallery stores its meta-data in a database like you do, and is pretty rich.

I don't think you'll find a "standard" schema, though. The closest thing I can think of is the EXIF meta-data format, which is embedded within image files themselves (by cameras, etc).

like image 21
skaffman Avatar answered Sep 22 '22 12:09

skaffman