如何计算与neo4j的朋友? [英] How to calculate mutual friends with neo4j?

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

问题描述

我想使用neo4j来管理用户之间的关系。

I want to use neo4j to manage relationship among users.

我如何让朋友共同使用它?

How can I get mutual friends using it?

推荐答案

最简单的方法是使用长度为2的最短路径算法,与两个用户在FRIEND_OF关系中。这些是通过恰好一个朋友跳连接两个用户的路径。

The easiest way would be to use the shortest path algorithm of length 2, with the two users, across FRIEND_OF relationships. Those are the paths that connect the two users via exactly one friend hop.

PathFinder<Path> finder = GraphAlgoFactory.shortestPath(
        Traversal.expanderForTypes( FRIEND_OF ), 2 );
Iterable<Path> paths = finder.findAllPaths( user1, user2 );

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

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