Try:

> START src=node(%d)
> MATCH src-[:KNOWS]-(friend)
MATCH (friend)-[KNOWS]-foaf
WITH distinct foaf,src // reduce the cardinality
MATCH (foaf)-[:KNOWS*..2]-(dest)
> 
> WHERE src <> dest AND NOT(src-[:KNOWS]-dest)
> RETURN count(DISTINCT id(dest)) as count_friends

Am 07.07.2014 um 15:09 schrieb Frandro <[email protected]>:

> I need to get the count of friends between 2 and 4 depths for all nodes with 
> the following query.
> 
> String query = String.format("START src=node(%d) MATCH src-[:KNOWS*2..4]-dest 
> WHERE NOT(src-[:KNOWS*0..1]-dest) RETURN count(DISTINCT id(dest)) as 
> count_friends", nodeId);
> 
> However, the problem is that traversing all the nodes and performing the 
> query are quite heavy.
> 
> Is there a better way to mitigate the heavily loading work? 
> 
> Is there a one query to get the result table containing 2 rows, a node and 
> count of friends as an alternative?
> 
> 
> 
> -- 
> 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.

-- 
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.

Reply via email to