我开发一个应用程序,这将有多个Facebook用户。
I'm developing one application, that will have multiple Facebook users.
我试图找出知道的最好的办法谁(从高达约20名单),拥有最连接(朋友)与他人从该列表中。
I'm trying to figure out the best way of knowing who (from a list of up to about 20), has most connections (friends) with others from that list.
所以,我们说这种情况:
So, let's say this situation:
名单= [A,B,C,D,E,F ...];
其中, A
是 B
,的C朋友
和 D
。而 B
是 A
的朋友, C
。
where, A
is friend of B
, C
and D
. And B
is friend of A
and C
.
我后来才知道,那 A
有3个连接, B
有2个,而 C
有2并使用 A
作为一个发布的东西。
I would then know, that A
has 3 connections, B
has 2, and C
has 2. And use A
as the one to post something.
我想在一些解决方案:
1)每个人在列表中,检查所有其他(使用图形API)的朋友连接。
1) For every person in the list, check for friend connection of all others (using Graph API).
2)缓存所有用户的所有朋友,在DB(也许的Neo4j
或的MongoDB
, SQL
...),然后横向搜索,寻找共同的朋友。
2) Cache all friends of all users, in the DB (maybe Neo4j
or MongoDB
, SQL
...), and then transverse the search, looking for common friends.
1问题:需要时间每次都做到这一点。 2个问题:DB将增长真正的大
Problem of 1: Might take time to do it every time. Problem of 2: DB will grow really big.
问:1和/或2好吗?有没有做这件事的任何其他方式? (我读Facebook的API,但并没有看到这样的事)。
Question: Is 1 and/or 2 ok? Is there any other way of doing it? (I read the Facebook API, but didn't saw anything like this).
您可以使用Neo4j的,你说。保存在Neo4j的人,包括他们的关系(友谊),然后使用查询与此类似:
You could use Neo4j as you stated. Save persons in neo4j including their relationships (Friendships) and then use query similar to this:
MATCH (a:Person)-[f:FRIENDS]-(b:Person)
WHERE Id(a) IN [1, 2, 3] AND Id(b) IN [1, 2, 3]
RETURN a.name AS name, count(f) AS numOfFriends
ORDER BY numOfFriends DESC