与Riak链接 - 搜索“共同朋友” [英] Link-walking with Riak - search for 'common friends'

查看:121
本文介绍了与Riak链接 - 搜索“共同朋友”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何一个与Riak一起工作的家庭成员都能解释如何在两个人之间寻找共同的朋友(例如,就像Facebook的共同朋友一样)?此外,计算要求理想情况下应该是最小的 - 即。服务器不需要经过很长的时间才能做计算。



我正在考虑将所有'人员'放在人员桶中,并且每个人员都会有一个朋友链接(这就像一对一 - 关系),那么对于每个人来说,都是反向关系 - 与另一个人链接(这就像一对一的关系)。我认为可以有效地做到这一点,计算/结果将立即可用,但只是无法弄清楚。



(好吧,我还没有真正开始使用Riak进行实际编码,所以对Riak的链接步行功能的更全面的解释将不胜感激。)



谢谢!

解决方案

我看到两种可能的解决方案:
$ b


  1. MapReduce大致适用于这种情况:

    • 两个输入,A和B被比较

    • 链接阶段获取他们的朋友ID

    • 将它们映射到元组{{FriendID,1})

    • 减少1s的总数
    • = 2

    • %%如果需要,可以将最后几步合并为一个 每个人都可以通过链接进行查询并与客户端的返回集相交 - 有点难看,但有效。


Can anyone familier with Riak explain how to do a link-walk to find common friends among two people (eg. just like Facebook's common friends)? Also, the computation requirement should ideally be minimal - ie. the server does not have to go through great length do do calculations.

I'm thinking of putting all 'persons' in a "people" bucket, and each 'person' will have a friends link (this is like a one-to-many relationship), then for each 'person' is reversed relationship-linked back to the other person (this is like a one-to-one relationship). I think it is possible to do this efficiently and calculation/result will be instantly available, but just can't figure it out.

(Alright, I have not exactly started real-coding with Riak, so a more thorough explanation on Riak's link walking feature would be appreciated.)

Thanks!

解决方案

I see two possible solutions:

  1. MapReduce job with approximately this scenario:
    • Two inputs with people A and B being compared
    • Link phase fetching their friends IDs
    • Map them to tuples {FriendID, 1}
    • Reduce sum the 1s
    • Reduce filter where sum = 2
    • %% Last few steps can be combined into one if necessary
  2. Just issue a link-walking query for each person and intersect returned sets on client - a bit ugly, but works.

这篇关于与Riak链接 - 搜索“共同朋友”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆