fix descendant queries

This commit is contained in:
2025-04-29 22:09:43 +02:00
parent 466ea365de
commit 69c43d6d79
2 changed files with 46 additions and 11 deletions

View File

@@ -1,11 +1,25 @@
MATCH (n:Person)
WHERE id(n) = $id
OPTIONAL MATCH (n)-[p:Parent*..]->(family:Person)
OPTIONAL MATCH (family)-[c:Child*1..4]->(children:Person)
OPTIONAL MATCH (family)-[s:Sibling]->(siblings:Person)
OPTIONAL MATCH (n)-[p:Parent*..]->(ancestors:Person)
optional MATCH (n)-[cc:Child*..]->(descendants:Person)
OPTIONAL MATCH (ancestors)-[c:Child*1..4]->(children:Person)
OPTIONAL MATCH (ancestors)-[s:Sibling]->(siblings:Person)
OPTIONAL MATCH (n)-[ds:Sibling]->(direct_siblings:Person)
WITH collections.to_set(collect(n)+collect(family)+collect(children)+collect(direct_siblings)+collect(siblings)) as people,
collections.to_set(collect(c) + collect(p) + collect(s) + collect(ds)) as relationships
WITH collections.to_set(
collect(n)+
collect(descendants)+
collect(ancestors)+
collect(children)+
collect(direct_siblings)+
collect(siblings)
) as people,
collections.to_set(
collect(c) +
collect(cc) +
collect(p) +
collect(s) +
collect(ds)
) as relationships
UNWIND people as ppl
RETURN collect({
id: id(ppl),

View File

@@ -1,14 +1,35 @@
MATCH (n:Person)
WHERE id(n) = $id
OPTIONAL MATCH (n)-[p:Parent*..]->(family:Person)
OPTIONAL MATCH (family)-[c:Child*1..4]->(children:Person)
OPTIONAL MATCH (family)-[s:Sibling]->(siblings:Person)
OPTIONAL MATCH (n)-[p:Parent*..]->(ancestors:Person)
optional MATCH (n)-[cc:Child*..]->(descendants:Person)
OPTIONAL MATCH (ancestors)-[c:Child*1..4]->(children:Person)
OPTIONAL MATCH (ancestors)-[s:Sibling]->(siblings:Person)
OPTIONAL MATCH (n)-[ds:Sibling]->(direct_siblings:Person)
OPTIONAL MATCH (family)-[fsp:Spouse]->(fspouse:Person)
OPTIONAL MATCH (ancestors)-[fsp:Spouse]->(fspouse:Person)
OPTIONAL MATCH (children)-[csp:Spouse]->(cspouse:Person)
OPTIONAL MATCH (n)-[sp:Spouse]->(spouse:Person)
WITH collections.to_set(collect(n) + collect(family) + collect(children) + collect(direct_siblings) + collect(fspouse) + collect(cspouse) + collect(spouse) + collect(siblings)) as people,
collections.to_set(collect(c) + collect(p) + collect(s) + collect(ds) + collect(fsp) + collect(csp) + collect(sp)) as relationships
WITH
collections.to_set(
collect(n) +
collect(descendants) +
collect(ancestors) +
collect(children) +
collect(direct_siblings) +
collect(fspouse) +
collect(cspouse) +
collect(spouse) +
collect(siblings)
) as people,
collections.to_set(
collect(c) +
collect(cc) +
collect(p) +
collect(s) +
collect(ds) +
collect(fsp) +
collect(csp) +
collect(sp)
) as relationships
UNWIND people as ppl
RETURN collect({
id: id(ppl),