linear combination of multiple properties

13 views
Skip to first unread message

gg4u

unread,
Aug 7, 2014, 7:04:12 PM8/7/14
to ne...@googlegroups.com
Hi folks!

so, today I was experimenting on obtaining a linear combination out of multiple types of properties.
Suppose you have multiple REL types, each with weighted properties.

I am trying to obtain a collection? of first neighbors to a node, ordered by the sum of two weights.

Here's what i've done:

MATCH (n:TYPE)
WHERE n.id = 'hellyeah'
OPTIONAL MATCH n-[r:P]-m
OPTIONAL MATCH n-[s:P2]-m
RETURN n,r,s,m

with this query, i get a table BUT all values of s are set as
NULL 
could you help me understand 
why?

thank you!

gg4u

unread,
Aug 10, 2014, 6:51:18 AM8/10/14
to ne...@googlegroups.com
Another simple attempt is to obtain different type of rel (r,s) going from a node to others (n-m).

I tried:

MATCH (n:TYPE)-[s:P1]-m
WHERE n.id = 'myname'
WITH n,s,m
MATCH m-[r:P2]-n
RETURN r,s

but it returns 0 rows,

Both the two matches from the node n.id, return not empty results in a single query (one match per query).

Why do r, s return no results with the combined query ?

Michael Hunger

unread,
Aug 10, 2014, 10:05:56 AM8/10/14
to ne...@googlegroups.com
That's probably because you'd want to use two different _m's_ otherwise the first m is reused for the second match.

MATCH (n:TYPE)
WHERE n.id = 'hellyeah'
OPTIONAL MATCH (n)-[r:P]-(m1)
OPTIONAL MATCH (n)-[s:P2]-(m2)
RETURN n,r,s,m1,m2

You can also optimize this a bit to do the second bit of matches not for each of the first
Something like this:

MATCH (n:TYPE)
WHERE n.id = 'hellyeah'
OPTIONAL MATCH (n)-[r:P]-(m1)
WITH n, collect({rel:r, node:m1}) as neighbours
OPTIONAL MATCH (n)-[s:P2]-(m2)
WITH collect({rel:s, node:m2}) + neighbours as neighbours
UNWIND neighbours  as nb
RETURN nb





--
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 neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

XDiscovery Team

unread,
Aug 12, 2014, 12:07:09 PM8/12/14
to ne...@googlegroups.com
mmm thank you Michael,
i will try this out.

i was also getting 0 rows because i noticed that i previously created relationshpis between nodes by limiting the results, so it was not said that, between two nodes, there would have been the two types of relationships I was looking for.


--
You received this message because you are subscribed to a topic in the Google Groups "Neo4j" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/neo4j/jTICIj3Baj4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to neo4j+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages