如何获得有相同兴趣的朋友的朋友? [英] How to get friends of friends that have the same interest?

查看:49
本文介绍了如何获得有相同兴趣的朋友的朋友?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

结交朋友非常容易,我觉得这很有效.

Getting friends of friend are pretty easy, I got this which seems to work great.

g.v(1).in('FRIEND').in('FRIEND').filter{it != g.v(1)}

但是我想做的只是让有相同兴趣的朋友成为朋友.下面,我希望乔被推荐为Moe,而不是Noe,因为他们的兴趣不一样.

But what I want to do is only get friends of friends that have the same interests. Below I want Joe to be suggested Moe but not Noe because they do not have the same interest.

推荐答案

您只需要扩展gremlin遍历即可遍历LIKES边缘:

You simply need to extend your gremlin traversal to go over the LIKES edges too:

g.v(1).in('FRIEND').in('FRIEND').filter{it != g.v(1)}.dedup() \
       as('friend').in('LIKES').out('LIKES').filter{it == g.v(1)}. \
       back('friend').dedup()

基本上,像以前一样,这会发送给朋友的朋友,并将位置保存在管道中的名称为friend.然后,他们会相互喜欢并搜索原始图片 源节点.如果找到一个,则跳回friend. dedup()只是删除重复项,可能会加快遍历速度.

Basically this goes out to friends of friends, as you had before and saves the position in the pipe under the name friend. It then goes out to mutual likes and searches for the original source node. If it finds one it jumps back friend. The dedup() just removes duplicates and may speed up traversals.

此方向性可能不是100%正确,因为您未在图表中指示边缘的方向.

The directionality of this may not be 100% correct as you haven't indicated direction of edges in your diagram.

这篇关于如何获得有相同兴趣的朋友的朋友?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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