implement family tree query

This commit is contained in:
2025-04-12 11:32:15 +02:00
parent e40e306faa
commit d054ec5c10
6 changed files with 115 additions and 33 deletions

View File

@@ -125,3 +125,17 @@ var GetProfileAdminsCypherQuery string
//
//go:embed queries/get_managed_profiles.cypher
var GetManagedProfilesCypherQuery string
// Requires id parameter.
//
// returns people, relationships
//
//go:embed queries/get_blood_relations_by_id.cypher
var GetBloodRelativesCypherQuery string
// Requires id parameter.
//
// returns people, relationships
//
//go:embed queries/get_family_tree_with_spouses.cypher
var GetFamilyTreeWithSpousesCypherQuery string

View File

@@ -1,4 +1,19 @@
MATCH (n:Person)-[p:Parent*1..]->(family:Person)
MATCH (n:Person)
WHERE id(n) = $id
OPTIONAL MATCH (n)-[p:Parent*..]->(family:Person)
OPTIONAL MATCH (family)-[c:Child*1..4]->(children:Person)
RETURN collect(family) + collect(children) + collect(n), collect(c) + collect(p)
OPTIONAL MATCH (family)-[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)) as people,
collections.to_set(collect(c) + collect(p) + collect(s) + collect(ds)) as relationships
UNWIND people as ppl
RETURN collect({
id: id(ppl),
first_name: ppl.first_name,
middle_name: ppl.middle_name,
last_name: ppl.last_name,
born: ppl.born,
died: ppl.died,
profile_picture: ppl.profile_picture
}) as people,
relationships;

View File

@@ -1,8 +0,0 @@
MATCH (n:Person)-[p:Parent*1..]->(family:Person)
WHERE id(n) = $id
OPTIONAL MATCH (family)-[c:Child*..4]->(children:Person)
WITH family, p, children, c, n
OPTIONAL MATCH (children)<-[p2:Parent]-(OtherParents:Person)
WITH family, p, children, c, OtherParents, p2, n
OPTIONAL MATCH (family)-[s:Spouse]-(spouse:Person)
RETURN family, p, children, c, OtherParents, p2, spouse, s, n;

View File

@@ -0,0 +1,22 @@
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)-[ds:Sibling]->(direct_siblings:Person)
OPTIONAL MATCH (family)-[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)) as people,
collections.to_set(collect(c) + collect(p) + collect(s) + collect(ds) + collect(fsp) + collect(csp) + collect(sp)) as relationships
UNWIND people as ppl
RETURN collect({
id: id(ppl),
first_name: ppl.first_name,
middle_name: ppl.middle_name,
last_name: ppl.last_name,
born: ppl.born,
died: ppl.died,
profile_picture: ppl.profile_picture
}) as people,
relationships;

View File

@@ -1,4 +0,0 @@
MATCH (n:Person)-[p:Parent*1..]->(family:Person)
WHERE id(n) = $id
OPTIONAL MATCH (family)-[c:Child*..4]->(children:Person)
RETURN family, p, children, c, n