neo4j - Filtering out nodes on two cypher paths -


i have simplified neo4j graph (old version 2.x) image 'defines' , 'same' edges. assume number on define edge property on edge

the queries run are:

1) find nodes defined both , b -- requried result: c, c, d

start a=node(885), b=node(996) match (a-[:define]->(x)<-[:define]-b) return distinct x

above works , returns c , d. want c twice since defined twice. without distinct on x, returns paths b.

2)find nodes not (defined both a,b or defined both a,b connected via same edge) -- required result: g

something like:

r1: match (a-[:define]->(x)<-[:define]-b) return distinct x

r2: match (a-[:define]->(e)-(:similar)-(f)<-[:define]-b) return e,f

(nodes defined - (r1+r2) )

3) find 'middle' nodes not have matching calls both , b --required result: c,g

i want output c due 1 define(either 45/46) not have matching define b. output g because there's no define g b. enter image description here

appreciate on this!

your syntax bit strange me, i'm going assume you're using older version of neo4j. should able use same approaches, though.

for #1, proposed match without distinct should working. thing can see adding missing parenthesis around , b node variables.

start a=node(885), b=node(996)  match (a)-[:define]->(x)<-[:define]-(b)  return x 

also, i'm not sure mean "returns paths b." can clarify that, , provide example of output?

as #2, we'll need several several parts query, separating them with accordingly.

start a=node(885), b=node(996)  match (a)-[:define]->(x)<-[:define]-(b) a, b, collect(distinct x) exceptions optional match (a)-[:define]->(x)-[:same]-(y)<-[:define]-(b) x not in exceptions , y not in exceptions a, b, exceptions + collect(distinct x) + collect(distinct y) allexceptions match (anode) anode not in allexceptions , anode <> , anode <> b return anode 

also, should using labels on nodes. final match match nodes in graph , have filter down otherwise.

edit

regarding #3 requirement, size() function helpful here, can size of pattern match, , tell number of occurrences of pattern.

the approach on query first collection of nodes defined or b, filter down nodes number of :defines relationships not equal number of :defines relationships b.

while use union in order union of nodes defined , union nodes defined b, neo4j's union support weak right now, doesn't let additional operations after union happens, instead have resort adding both sets of nodes same collection unwinding them rows.

start a=node(885), b=node(996)  match (a)-[:define]->(x) a, b, collect(x) middlenodes match (b)-[:define]->(x)  a, b, middlenodes + collect(x) allmiddles unwind allmiddles middle distinct a, b, middle size((a)-[:define]->(middle)) <> size((b)-[:define]->(middle)) return middle 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -