我的Neo4j实例中填充了来自当地大学的完整校友数据集。一小部分(15K)的(248K)节点(n:Alumni)包含一个twitter user_name。我的目标是使用GITHUB应用程序(TWIITER到NEO4J)加载和链接twitter screenNames以获取关系数据。我的问题是下面的查询(包含在GITHUB应用程序的java脚本中)Cypher创建了与Alumni screen_name不匹配的不需要的Follower / Following节点。我想写一个只允许从应用程序创建关系的查询。让我知道这是否更清楚......
MERGE (targetNode:Person {screen_name: {screenName}})
FOREACH (friend in {userList} |
MERGE (friendNode:Person {screen_name: friend.screen_name})
ON CREATE SET friendNode=friend
MERGE (targetNode)-[:FOLLOWS]->(friendNode))
这是我的想法 - 我将MERGE设置为MATCH Alumni
MATCH (targetNode:Alumni {screen_name: {screenName}})
WHERE targetNode:Alumni.screen_name = {screen_name}
FOREACH (friend in {userList} |
MATCH (friendNode:Alumni {screen_name: friend.screen_name})
SET friendNode=friend
MERGE (targetNode)-[:FOLLOWS]->(friendNode))
感谢您的任何想法...
var multiline = require('multiline');
exports.upsertOne = multiline(function(){/*
MERGE (n:Person {screen_name: {screenName}})
ON CREATE SET n+={userMap}
RETURN n
*/});
/*
* Parameters are:
*
* screenName - string, the handle of the person to attach followers to
* userList - array of objects, people to merge and create relationships
*/
exports.upsertManyAndFollows = multiline(function() {/*
MATCH (followeeNode:Alumni {screen_name: {screenName}})
UNWIND {userList} as follower
MATCH (followerNode:Alumni {screen_name: follower.screen_name})
SET followerNode=follower
MERGE (followerNode)-[:FOLLOWS]->(followeeNode)
*/});
/*
* Parameters are:
*
* screenName - string, the handle of the person to attach followers to
* userList - array of objects, people to merge and create relationships
*/
exports.upsertManyAndFriends = multiline(function() {/*
MATCH (targetNode:Person {screen_name: {screenName}})
UNWIND {userList} as friend
MATCH (friendNode:Person {screen_name: friend.screen_name})
SET friendNode=friend
MERGE (targetNode)-[:FOLLOWS]->(friendNode)
*/});
/*
* Parameters are:
*
* screenName - string, the handle of the person that is at the center of the graph.
*
*/
答案 0 :(得分:0)
您可以尝试使用此功能,但请确保使用正确的屏幕名称(查询中同时包含{screenName}
和{screen_name}
,因此其中一个错误)。
如果你的:已经创建了校友节点,这应该可行。
MATCH (targetNode:Alumni {screen_name: {screenName}})
UNWIND {userList} as friend
MATCH (friendNode:Alumni {screen_name: friend.screen_name})
SET friendNode=friend
MERGE (targetNode)-[:FOLLOWS]->(friendNode)