查找最近的&最近的帖子,限制 20
假设我在 MongoDB 中有一堆帖子(用于提要,例如 Twitter/Facebook/foursquare 提要),并且每个帖子都有一个 位置 & 时间戳。
获取最新信息的最佳方式是什么?最近的帖子,限制为 20 个帖子?
这也是一个主观问题。假设您可以指定 $maxDistance
以及从现在起的最长时间(我不确定您会如何执行其他操作。)。你会如何指定它们?您会按最近的或最接近的排序,还是保持随机或以其他方式排序?您认为哪种排序算法最有趣?
Let's say I have a bunch of posts (for a feed, like a Twitter/Facebook/foursquare feed) in MongoDB, and each post has a location & a timestamp.
What's the best way to get the most recent & closest posts, limited to 20 posts?
This is also a subjective question. Let's say that you can specify $maxDistance
and the max time since now (I'm not sure how you'd do it otherwise.). How would you specify them? Would you sort by most recent or closest, or keep it random or sort some other way? Which sorting algorithm do you think is most interesting?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想您最终会得到一个具有两个离散排名维度的帖子列表,即:
单位是什么并不重要,比如秒和米。如果您希望两者都影响排序排名,那么您最终会得到一个排名算法,最简单的是这样的:
其中 C1 和 C2 是您可以调整的常量调整权重。这些值将取决于您使用的单位以及您分配给每个维度的排名影响力。
另一种选择是先按时间聚合排序,然后按距离排序,因此今天的所有帖子均按距离排序;接下来是昨天的按距离排序,依此类推。反之亦然,先按距离范围排序,然后按年龄排序,因此(0 - 1000m)内的所有内容均按年龄排序;其次是全部在(1001 - 2000m)以内,依此类推。
I suppose you ultimately end up with a list of posts that have two discrete ranking dimensions, i.e.:
Doesn't really matter what the units are, lets say seconds and metres. If you want both to affect the sorting rank then you end up with a ranking algorithm, at its simplest something like this:
Where C1 and C2 are constants you can tweak to tune the weightings. The values will depend what units you're using, and how much ranking influence you assign to each dimension.
Another option could be ordering first by a time aggregate then distance, so all posts from today ordered by distance; followed by yesterday's ordered by distance, and so on. Or vice-versa, ordering by a distance range, then age, so all within (0 - 1000m) ordered by age; followed by all within (1001 - 2000m), and so on.