cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Group NODES by CONTAINS

MATCH (l:WORD)<--(k:SENTENCE)
WITH l
MATCH (l)-[*]-(n:SENTENCE)
WHERE n.name CONTAINS l.name
WITH n.name AS NodeContainingTheWords, l.name AS TheWord
RETURN NodeContainingTheWords, TheWord

Returns the following

I want to group 1 and 2 so that I can ORDER BY which :SENTENCE CONTAINS the most WORDS

1 ACCEPTED SOLUTION

Hello @VilladsClaes

You can aggregate by words or sentences with collect():

RETURN NodeContainingTheWords, collect(TheWord) AS words

Or

RETURN TheWord, collect(NodeContainingTheWords) AS sentences 

Regards,
Cobra

View solution in original post

1 REPLY 1

Hello @VilladsClaes

You can aggregate by words or sentences with collect():

RETURN NodeContainingTheWords, collect(TheWord) AS words

Or

RETURN TheWord, collect(NodeContainingTheWords) AS sentences 

Regards,
Cobra