Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-25-2022 10:34 AM - edited 08-25-2022 10:35 AM
Hi,
I want to find the nearest neighbours with the same value of relationship property. Eg. the relationship PARENT has the property "color" and that property has values as "yellow", "green" and "red". So I want to find the the nearest neighbours only with the same color.
I have already wrtite some code, which work fine. But that code return nodes with mixed relationship colors.
Question: How to expand the code to implement thatt restriction ? Perhaps a for each construnt for each value of color ?
Thanks in advance,
Michel
THis question is related to How to get the first node from relationship with property value
match (p1:MAGIC{aprop:'xyz'})
CALL apoc.path.expandConfig(p1, {
relationshipFilter: "<PARENT",
labelFilter: "/MAGIC",limit:1
})
yield path1
SET p1.beforeprop = last(nodes(path1)).aprop
==========================================================
match (p2:MAGIC{aprop:'xyz'})
CALL apoc.path.expandConfig(p2, {
relationshipFilter: "PARENT>",
labelFilter: "/MAGIC",limit:1
})
yield path2
SET p2.afterprop = last(nodes(path2)).aprop
08-25-2022 08:34 PM
I don't fully understand the requirement, but I will assume that both the relations property 'color' and the related node's property 'color' are both lists of colors, and that you want related nodes that have the identical list of colors. If so, try the following:
match (n:MAGIC{aprop:'xyz'})
match p = (n)-[r:PARENT]-(p:MAGIC)
where all(x in r.color where x in p.color)
and size(r.color) = size(p.color)
return p
08-25-2022 11:54 PM - edited 08-25-2022 11:55 PM
Hi @glilienfield ,
thanks for your effort. Sorry, the requirements were not enough precise: Only the color of relationship shold be the same. What I need the nearest neighbours in both directions. Could you please extend your code for getting both neighbours ? In only one query, not using two queries (s. my code).
Thanks in advance,
Michel
All the sessions of the conference are now available online