So I have a list of name nodes in an index called "names":
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
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:
"foo bar" --> "bar baz"
"foo bar" --> "bar qux"
"bar baz" --> "baz qux"
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:
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.)