Here is my schema. The problem: given list of X nodes, which are children of C,D,E,F,G find node B which has the most X nodes connected through nodes C,D,E,F,G.
After that, I need to go 1 level higher, meaning, I need to find node A. How the cypher queries would look like ?
Ran this:
match (a:GrandChild)-[]-(b:GrandChild2)
where b.grandChild2 in['C1', 'E1', 'G1']
match (c:Child)-[]-(a)
with distinct c.child as chld1, count(distinct a) as cnt
return chld1, cnt order by cnt desc
You did not provide node labels, nor relationship types, so I wrote a generic query you can modify with your specific constraints on node labels and relationships types. I also assumed the letters represented the nodes 'name' property. Change this to match your data model.
with['C','D','E','F','G'] as nodes
match(b:B)-->(n)
where n.name in nodes
with b, count(*) as numOfNodes
order by numOfNodes desc
limit 1
match(a:A)-->(b)
return a.name, b.name, numOfNodes
Now, given list of kewords for example ['i', 'love', 'neo4j', 'its', 'a', 'great', 'tool'], I want to find best corresponding song and genere, probbably based of the number of connections from keywords to specific song.
with ['i','love','neo4j','its','a','great','tool'] as keywords
match(s:SONG)-[:HAS_X|HAS_LYRICS|HAS_INSTRUMENT|HAS_AUTHOR]->()-[:HAS_KEYWORD]->(k:KEYWORD)
where k.name in keywords
with s, count(*) as cnt
order by cnt desc
limit 1
match(s)<-[:BELONGS_TO]-(g:GENRE)
return s.name, g.name, cnt