Using RELATE with multiple index lookups

31 views
Skip to first unread message

Josh Adell

unread,
Aug 1, 2012, 11:20:24 PM8/1/12
to ne...@googlegroups.com
So I have a list of name nodes in an index called "names":
"foo bar"
"bar baz"
"baz qux"
"bar qux"
"qux foo"

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:

"foo bar" --> "bar baz"
"foo bar" --> "bar qux"
"bar baz" --> "baz qux"
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

Michael Hunger

unread,
Aug 2, 2012, 3:54:05 AM8/2/12
to ne...@googlegroups.com
I think in this case you don't need foreach in this case:

> START named=node:names("first:*")
WITH named
> START next=node:names("first: " + current.last), prev=node:names("last: " + current.first)
> RELATE current -[:LEADS_TO]-> next
> RELATE prev -[:LEADS_TO]-> current


Hope that works.

Can you try to create a console example that we can work on? (The console is auto-indexing each property so if you create a node with the first and last properties you should find them in the node_auto_index)

Michael

Josh Adell

unread,
Aug 2, 2012, 7:02:58 PM8/2/12
to ne...@googlegroups.com
This is what I have so far:


I think I'm getting a parse error because it doesn't like the string concatenation in 'next=node:node_auto_index("first:"+named.last)'

-- Josh

Peter Neubauer

unread,
Aug 20, 2012, 10:21:55 AM8/20/12
to ne...@googlegroups.com
Guys,
is this something that should be possible - use identifiers and
functions in the index calls? Andres?

Cheers,

/peter neubauer

G: neubauer.peter
S: peter.neubauer
P: +46 704 106975
L: http://www.linkedin.com/in/neubauer
T: @peterneubauer

Wanna learn something new? Come to @graphconnect.
Reply all
Reply to author
Forward
0 new messages