设计博客网站的键值数据库中存储数据的数据结构
我需要使用键值数据库作为主数据库从头到尾创建一个博客网站。但是,当我根据项目需求为项目创建数据结构来存储和查询数据时,我无法思考如何设计两个函数“为最喜欢的博客文章投票”和< strong>“按类别搜索博客文章”。对于“为最喜欢的博客文章投票”功能,需求中表示“网站允许用户对最喜欢的博客文章进行投票,如果任何博客文章达到150票,则将其排名为感兴趣的博客。如果网站有大约30票每天感兴趣的博客文章,网站会将这30篇博客文章放在主页之外,并称它们为“最感兴趣的50篇博客文章”,以后每篇博客文章都会有相应的分数进行评估,并且网站不会允许。用户对一篇博客文章进行投票很多次”
现在我需要设计像上面两个函数那样的数据结构。但我不知道,尤其是“为最喜欢的博客文章投票”功能。
例如,通过“每个博客文章都会有读者的评论”功能,我将在键值数据库中设计数据结构,例如:
CMT:$BLOG_ID :$RATING: [ {"VIEWER_ID":"", "timestamp":"","image":"","comment":""},{..},{...}].
任何人都可以对此给出提示吗?太感谢了。
I need to create a blogging website from end to end by using a key-value database as a primary database. But when I create the data structure for the project to store and query data based on project requirements, I cannot think how can I design the data model for 2 functions "vote for the favorite blog post" and "search blog posts by categories". For the function "vote for the favorite blog post", the requirement says "The website allows users to vote favorite blog post, if any blog post reaches 150 votes, it will be ranked as a blog of interest. If the website has about 30 blog posts of interest per day, the website will place these 30 blog posts off the main page and called them are "Top 50 blog posts of interest". Each blog post will has the corresponding score to evaluate later. And the website will not allow user to vote one blog post many times"
Now I need to design the data structure like that for 2 functions above. But I don't have any idea, especially function "vote for the favorite blog post".
For example, with the function "Each blog post will have comments from reader" I will design the data structure in key-value databases like:
CMT:$BLOG_ID:$RATING: [ {"VIEWER_ID":"", "timestamp":"","image":"","comment":""},{..},{...}].
Can anyone give a hint about this? Thank you so much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
blog:id:votes
处的计数器,当博客被点赞时该计数器会递增。如果达到 150 票则递增,然后将该 id 添加到 50 票的列表中另一把钥匙
创建一个从类别到博客文章 ID 的倒排索引
因此,如果博客是使用类别食物和音乐创建的 - 您应该生成 2 个键,例如
music:blogId
和food:blogId
然后,要进行搜索,请对类别进行前缀扫描:* 并获取与类别匹配的博客 ID
A counter at
blog:id:votes
which is incremented when a blog is upvotedAfter incrementing if it has reached 150 votes then add the id to the list of 50 which will be at another key(s)
Create an invertex index that goes from categories to the blog post id
So if a blog is created with categories food and music - you should generate 2 keys like
music:blogId
andfood:blogId
Then to search you do a prefix scan over the categories:* and grab the blog ids that match the category