我计划使用以下公式来计算“趋势”帖子:
Trending Score = (p - 1) / (t + 2)^1.5
p = 来自用户的投票(点数)。t = 自提交以来的时间,以小时为单位。
我正在寻找有关如何构建我的数据库表的建议,以便我可以使用 DynamoDB(来自 Amazon 的一种 nosql 数据库服务)查询趋势帖子。
DynamoDB 要求表中的每个项目都有一个主键。主键可以由两部分组成:哈希属性(字符串或数字)和范围属性(字符串或数字)。每个项目的哈希属性必须是唯一的并且是必需的。Range Attribute 是可选的,但如果使用 DynamoDB 将在 Range Attribute 上构建一个排序的范围索引。
我想到的结构如下:
表名:用户
HashAttribute: user_id
RangeAttribute: NONE
OtherFields: first_name, last_name
表名:帖子
HashAttribute: post_id
RangeAttribute: NONE
OtherFields: user_id,title, content, points, categories[ ]
表名:类别
HashAttribute: category_name
RangeAttribute: post_id
OtherFields: title, content, points
表名:计数器
HashAttribute: counter_name
RangeAttribute: NONE
OtherFields: counter_value
因此,这是我将使用下表设置发出的请求类型的示例(例如:user_id=100):
用户操作 1:
用户创建一个新帖子并将帖子标记为 2 个类别(棒球、足球)
查询(1):
检查 counter_name='post_id' 和 increment+1 的当前值并使用新的 post_id
查询 (2):将以下内容插入 Posts 表:
post_id=value_from_query_1, user_id=100, title=user_generated, content=user_generated, points=0, categories=['baseball','soccer']
查询(3):
将以下内容插入到类别表中:
category_name='baseball', post_id=value_from_query_1, title=user_generated, content=user_generated, points=0
查询(4):
将以下内容插入到类别表中:
category_name='soccer', post_id=value_from_query_1, title=user_generated, content=user_generated, points=0
最终目标是能够进行以下类型的查询:
1. 查询热门帖子
2. 查询某个类别
的帖子 3. 查询最高分值的帖子
有谁知道我可以如何构建我的表格,以便我可以查询热门帖子?还是我放弃了通过切换到 DynamoDB 来做的事情?