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

Hello @VilladsClaes :slight_smile:

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

RETURN NodeContainingTheWords, collect(TheWord) AS words

Or

RETURN TheWord, collect(NodeContainingTheWords) AS sentences 

Regards,
Cobra

1 Like