如何实现评论引用功能?

发布于 2024-08-20 05:29:15 字数 528 浏览 7 评论 0原文

我们允许在我们的网站(如博客)上发表评论。现在我们想改变它,以便人们可以评论其他评论。

我们的表看起来像这样:

ID    |    CommentID    |    Comment     |    User     |     Date
-------------------------------------------------------------------------
1001  |        1        |    Nice site   |     Me      |     20.01.2010
1001  |        2        |    Thx!        |     You     |     21.01.2010

我提出了两个选项:

1)创建一个 ParentCommentID 并用它决定评论如何从上到下列出。

2) 将您正在评论的评论与您自己的评论一起存储,并带有一些 [QUOTE] 标签或其他内容。

有什么好的建议来解决这个问题吗?

We allow commenting on our website (like a blog). Now we want to change it so that people can comment other comments.

Our table looks something like this:

ID    |    CommentID    |    Comment     |    User     |     Date
-------------------------------------------------------------------------
1001  |        1        |    Nice site   |     Me      |     20.01.2010
1001  |        2        |    Thx!        |     You     |     21.01.2010

I came up with two options:

1) Create a ParentCommentID and with that decide how the comments are listed from top to bottom.

2) Store the comment you're commenting together with your own comment with some [QUOTE]-tags or something.

Any good tips to solving this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

烧了回忆取暖 2024-08-27 05:29:15

我会使用一个 ParentCommentID 作为返回该表的 CommentID 的外键。这将强制引用完整性,并且您将避免一些重复。

如果十个人引用一条评论,则使用选项 2 将该评论复制十次。在选项一中,您只有 10 个 FK。

单个评论中允许的字符越多,选项 2 中每个引用的重复内容就越多。

选项 1 还允许您进行更多报告。您可以更轻松地查询以找出哪些评论被引用最多。

I would go with a ParentCommentID that acts as a foreign key back to that table's CommentID. That will enforce referential integrity, and you'll avoid some duplication.

If ten people quote a comment, it is replicated ten times with option 2. In option one, you only have ten FKs.

The more characters you allow in a single comment, the more duplication you'll have per quote with option 2.

Option 1 also allows you to do more reporting. You can more easily query to find out which comments are quoted the most often.

岛徒 2024-08-27 05:29:15

您真正要问的是您希望数据库表如何标准化。我想说,这是一个基于诸如您的网站有多大以及您认为应该进行标准化的程度等因素的判断。使用类似的示例,在我们的论坛中,我们将发布线程的用户名存储在线程表中 - 出于性能原因,这是非规范化的 - 有时您只是不想进行大量连接。维基百科关于数据库规范化的文章有更详细的介绍。

我个人的看法是,我会存储带有引用的评论,因为这可以防止人们更改他们已经编写的内容(忍者编辑)来混淆争论/讨论;)

What you're asking really is how normalized you want your database table to be. I would say this is a judgement call based on factors such as how large your website is and how far you believe you should take normalization. To use a similar example, in our forums we store the username of who posted a thread in the thread table - this is de-normalized for performance reasons - sometimes you just don't want to be doing lots of joins. The Wikipedia article on database normalization goes into more detail.

My personal take is I would store the comment with the quote inside it, as this prevents people from changing something they've already written (ninja editing) to obfuscate arguments/discussions ;)

世俗缘 2024-08-27 05:29:15

听起来我们需要先收集更多需求!

  • 您使用什么类型的数据库(MySQL、MSSQL 等)?什么版本?例如,SQL Server 2008 有一个内置的 HierarchyId 数据类型来处理此类事情。
  • 您想要支持多于一层的嵌套评论(即完整的分层回复树)吗?
  • 您有什么样的性能要求?这必须具有多大的可扩展性和鲁棒性?
  • 您是否需要报告回复,或者回复是否严格来说是一段内容?例如,vBulletin 具有简单的引用回复,只是消息的一部分,而某些博客评论系统会在您收到回复时提醒您,并且您可以单独查看对评论的回复。

Sounds like we need to do some more requirements gathering first!

  • What type of database are you using (MySQL, MSSQL, etc)? What version? SQL Server 2008, for example, has a built in hierarchyId datatype for this sort of thing.
  • Do you want to support more than one level of nested comments (ie. full hierarchical reply trees)?
  • What kind of performance requirements do you have? How scalable and robust does this have to be?
  • Would you ever need to report on replies or would a reply be strictly a piece of content? For instance, vBulletin has simple quoted replies that are just part of the message, whereas some blog commenting systems will alert you when you get a reply, and you can view replies to your comments separately.
风和你 2024-08-27 05:29:15

Parentid 是一个不错的选择。您还可以存储时间和日期,以找出已发布回复的层次结构,甚至可以使用 CommentID 字段。

The parentid is a good option. You can also store time along with date to find out the hierarchy of posted reply or you can even use the CommentID field for it.

奶气 2024-08-27 05:29:15

如果页面上未显示评论 ID,您始终可以应用 IP 地址或应用程序版本等编号方案。 IE,CommentID 2.1是第一条评论对第二条评论,2.2是第二条评论对第二条评论。因为不需要太多的字符串标记器来确认 CommentID 3.1.7 是帖子的第一条评论和第二条评论的第七条评论。一旦将其标记为整数,排序就变得轻而易举。

If the comment ID isn't displayed on the page you could always just apply a numbering scheme like an IP address or an application version. I.E., CommentID 2.1 is the first comment on the second comment, and 2.2 is the second comment on the second comment. As it wouldnt take much of a string tokenizer to acknowledge CommentID 3.1.7 is the seventh comment on the first comment on the second comment of a post. Sorting becomes a breeze once you tokenize it into integers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文