Reputation: 5719
Imagine a huge graph of users each with one attribute called email. Now imagine I have to group those that use gmail under one group called "google_mail", and those that use "yahoo" into a group called "yahoo_mail".
How do I traverse the graph that is disconnected (no root node to go visit each user node and not every user is connected (i.e. we could have completely disjointed graphs of users). I want to avoid loading all those users into memory. Is this possible?
Upvotes: 1
Views: 1001
Reputation: 39925
In Neo4j 2.0 there is a new feature called labels which seems to be a good fit for your use case, see http://docs.neo4j.org/chunked/milestone/graphdb-neo4j-labels.html.
To assign all nodes having an email containing "gmail" a GoogleMail
label you might use:
START n=node(*)
WHERE n.email =~ '.*@gmail.com'
SET n :GoogleMail
START n=node(*)
WHERE n.email =~ '.*@yahoo.com'
SET n :Yahoo
Be aware that depending on your graph size you might use LIMIT
and SKIP
to apply the change not in a single huge transaction.
To get a list of all gmail users:
MATCH (n:GoogleMail) RETURN n
Upvotes: 6