Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-06-2022 02:18 AM
Hi, could you please help with finding query ? I am absolute beginner.
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 ?
Thanks for help
Solved! Go to Solution.
12-06-2022 06:42 PM
You can try something like this.
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
12-06-2022 11:17 AM
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
12-06-2022 11:36 AM
I am rather trying specify X nodes as input to the query. Something like in here
https://community.neo4j.com/t5/neo4j-graph-platform/cypher-query-to-match-draw-the-path-from-a-leave...
However without relationship between yellow nodes.
12-06-2022 12:29 PM
Try this:
I created this:
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
Result:
12-06-2022 12:52 PM
Ok I found some more professional tool to explain my problem.
Here is schema of my database:
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.
How is that sounds ?
12-06-2022 02:50 PM - edited 12-06-2022 02:51 PM
Try this:
I created this:
Ran this query:
with ['i', 'love', 'neo4j', 'its'] as s1
match (a:Keyword) where a.keyword in s1
match (b:Song)-[]-(c)-[]-(a)
return a, b, c
Result:
12-06-2022 06:42 PM
You can try something like this.
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
12-07-2022 12:37 AM
Perfect ! Thanks so much
All the sessions of the conference are now available online