如何计算与neo4j的共同好友? [英] How to calculate mutual friends with neo4j?
本文介绍了如何计算与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屋!
查看全文