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

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

问题描述

结交朋友的朋友很容易,我得到了这个似乎很好用.

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)}

但我想做的只是结交志趣相投的朋友.下面我希望 Joe 被推荐为 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天全站免登陆