I am trying to find an efficient way of traversing all nodes and find
transitive relationships of length 2 on my database. Currently, I am using
query1 to compute the new properties for the new relationship and query 2
to add the relationship into the database
query1:
MATCH (a:USERS) - [ab:TRUST] -> (b:a:USERS) - [bc:TRUST] -> (c:a:USERS)
WHERE a <> c AND exists(ab.conversationalTrust) AND exists(bc.
conversationalTrust)
WITH id(a) AS a, id(c) AS c, ab.conversationalTrust AS ab,
bc.conversationalTrust
AS bc
WITH a, c, sum(ab*bc)/ sum(ab) AS t1, sum(ab*ab*bc)/ sum(ab) AS t2, 10^4 AS
factor
RETURN a, c, round(factor * t1)/factor AS simpleTransitiveTrust, round(factor
* t2)/factor AS weightedTranstiveTrust;
Java code that pack the above results into batches and pass it to query 2
long userAId = (long) map.get("a");
long userBId = (long) map.get("c");
double simpleTransitiveTrust = (double) map.get(TwitterProperties.
SIMPLE_TRANSITIVE_TRUST);
double weightedTransitiveTrust = (double) map.get(TwitterProperties.
WEIGHTED_TRANSITIVE_TRUST);
Object[] params = {userAId, userBId, simpleTransitiveTrust,
weightedTransitiveTrust};
return params;
query2:
UNWIND {params} as params
MATCH (a:USERS),(b:USERS)
WHERE id(a) = params[0] and id(b) = params[1]
MERGE (a) - [r:TRUST] -> (b)
SET r.simpleTransitiveTrust= params[2], r.weightedTranstiveTrust= params[3]
RETURN count(*) as c
I have two questions:
1) Is it more efficient to do everything in Cypher, i.e. combine query 1
and query 2?
2) Is the above way the best way to go through all transitive
relationships? Since I have more than 500k nodes in my database, it takes a
very long time to process everything, so I am hoping there's a way to speed
it up. Would the traversal framework in java be of any use? If so, how
should I use it in this case.
3) Without specifying where to start, does neo4j automatically goes through
all possible pairs of nodes for a and c to find transitive relationships
between them?
Thank you very much in advance for helping me out.
Cheers,
Cherie
--
You received this message because you are subscribed to the Google Groups
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.