So I have a list of name nodes in an index called "names":
"foo bar"
"bar baz"
"baz qux"
Each name node is indexed with a key "first" which is the first word in the name, and "last" which is the last word in the name, and each node has properties on it containing the first and last words. The following Cypher works:
START named=node:names("first:bar") RETURN
named.name
returns "bar baz" and "bar qux". So all that is working
Now what I want to do is use Cypher to link together the name nodes such that the last word of a node is the first word of the outgoing node. In the end, I should have a graph that looks like:
etc...
I think I should be able to do this in Cypher with FOREACH and RELATE, but I'm unsure of the exact syntax. The following is semantically what I want, but is not syntactically correct:
START named=node:names("first:*")
FOREACH (current in nodes(named):
START next=node:names("first: " + current.last), prev=node:names("last: " + current.first)
RELATE current -[:LEADS_TO]-> next
RELATE prev -[:LEADS_TO]-> current
)
I could do this all in the application, but I was hoping for a more elegant solution using Cypher (preferably one that is idempotent.)
Any ideas?
Thanks!
-- Josh