标签系统中标签的ID[英] ID for tags in tag systems

本文是小编为大家收集整理的关于标签系统中标签的ID的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我正在实现类似于stackoverflow标签系统的标签系统.我正在考虑何时存储标签并与问题有关,该关系将直接与标签名称直接与之相关,或者最好创建一个字段tagid来将问题与标签"链接"?看起来直接链接到标签名称很容易,但是看起来不好,主要是为什么在使用统计信息和/或标签分类(IMHO)时很难管理此问题的原因.另一个问题是当管理员决定"修复"标签名称时.如果没有与标签名称分开的tagid,那么我将更改表的键...

你的想法是什么?

感谢所有答复.我将删除这篇文章,因为还有另一个具有相同主题的帖子.我想知道为什么搜索和建议没有为我显示结果...

推荐答案

请访问这些相关的相关问题,所以问题:

其他推荐答案

您的问题中的最后一句话似乎可以回答.假设标签存储在标签表中,我将始终有一个ID列(INT或GUID)和标签名称的VARCHAR/String列.将某些实体与一个或多个标签相关联的多个对数(交界表)将具有包含ID的"其他实体"和标签ID的两个列. 然后,在不触摸钥匙的情况下,很容易编辑标签(例如,纠正拼写错误).当使用包括连接到连接表的查询时,您应该获得更好的性能,这也意味着您正在更好地标准化数据.

记住," 钥匙,整个钥匙,全部钥匙,没有钥匙,所以帮我codd "! :)

其他推荐答案

如果您预见了许多标签,并且正在使用关系数据库,则使用数据库内部支持本地支持的ID(例如RID)可能会为您提供更好的性能.

如果这不是一个问题:使用简单的简短标签名称.您可以给标签长名,这些名称也将在用户界面中显示在有意义的地方(例如,在创建新标签时向用户询问一个).您更有可能编辑长名字,这没有直接指的是,所以这不是问题.

顺便说一句,如果您使用的是关系数据库,将标签名称与所有参考的所有引用一起使用简单查询可能不是很难要经常完成,您需要为其进行优化.并考虑您可能也需要合并的重复标签,因此您可能还是希望能够做到这一点.

本文地址:https://www.itbaoku.cn/post/597630.html

问题描述

I'm implementing a tag system similar to StackOverflow tag system. I was thinking about when storing the tags and relating to a question, that relationship will be directly with the tag name or it's better create a field tagID to "link" the question with the tag? Looks that linking directly to tag name is easier, but it doesn't look good, mainly why when working with statistics and/or tag categorization (IMHO) can be hard to manage this. Another problem is when one admin decides "fix" a tag name. If there isn't a tagID separated from tag name, then I will be changing the key of the table...

What's your thoughts?

Thanks for all replies. I will delete this post since there is another posts with the same subject. I wonder why the search and the suggestion doesn't show it results for me...

推荐答案

Have a look at these related earlier SO questions:

其他推荐答案

Your last sentence in your question seems to answer it. Assuming the tags are stored in a tag table, I would always have an ID column (int or GUID) and the varchar/string column for the tag name. The many-to-many (junction table) that would relate some other entity to one or more tags would have two columns containing the ID's the "other entity" and the tag's ID. It's then easy to edit a tag (to correct a mis-spelling for example) without touching the key. You should get much better performance when using queries that include joins with your junction table and it also means you're normalizing your data better.

Remember, "the key, the whole key and nothing but the key, so help me codd"! :)

其他推荐答案

If you foresee many tags, and are using a relational database, using an ID that the database supports natively (e.g. RID) internally may just give you better performance.

If that's not a concern: go by simple short tag names. You can give the tags long names which will be displayed in the user interface too where it makes sense (e.g. ask the user for one when creating a new tag). You are more likely to have to edit the long names, which nothing refers to directly, so this is not a problem.

Aside, if you are using a relational database, it is probably not very difficult to change a tag name together with all its references with a simple query, it may just be a slightly more expensive operation, but it is probably not going to be done frequently enough that you need to optimize for it. And consider that you may have duplicate tags that you will want to merge too, so you might want to be able to do that anyway.