Pking
Pking

Reputation: 963

Tagging system design issues

I'm working on a news site and I'm thinking of implementing a tagging system (similar to this site) where you'll be able to categorize news by different category types such as: newscategory (economy, politics, etc.) but also things such as language it was written in and type of news article (editorial, feature story, etc.).

How should I distinguish between these different category types? Should I have one table of tags for each category type, or should I keep everything in one table and have a tag-prefix such as "language:en", "category:economy"? The second solution seems more flexible because I can add more caregory types just by appending a prefix. However the first solution feels more structured and easier to work with.

Also, I wonder how you determine when something should be represented as a tag or when it should be a column value/record in the database (e.g. should the language be a tag or do I have language column in my "News" table?). I'm not sure where to draw the line.

Thanks

Upvotes: 2

Views: 432

Answers (1)

Johan
Johan

Reputation: 5053

Would it be sufficient to say that the tags themselves could be ordered in a hierarchy? If so, just add a parent_tag_id to your tags table.

id  name          parent_tag_id
-------------------------------
1   language      null
2   english       1
3   french        1
4   newscategory  null
5   economy       4
6   politics      4

You might think of columns as static fields and rows as dynamic. Keep the number of columns low. Language might be a column of all fields in the table should be associated with a language.

Upvotes: 1

Related Questions