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.

Weekly Challenge #4 Movies with limited actors

TrevorS
Community Team
Community Team

Welcome back to our Weekly challenge series!
In keeping with the theme so far, this week's challenge is to tune the provided query.

Here's what you need to do!

  • Create a recommendations sandbox at sandbox.neo4j.com.
  • Here is a query that returns a row for every movie that has 2 or fewer actors. How can you make this query perform better?
"PROFILE
MATCH (m:Movie)<-[:ACTED_IN]-(a:Person)
WITH  m, collect(a.name) as actorNames
WHERE size(actorNames) <= $maxActors
RETURN  m.title, m.year, actorNames"

Solutions submitted between 8/30 and 9/9 will be eligible for a Neo4j T-Shirt drawing!

Show us your ways to improve the query!

TrevorS
Community Specialist
3 REPLIES 3

Hello @TrevorS 😊

:param maxActors => 2;

MATCH (m:Movie) 
WHERE 0 < size((m)<-[:ACTED_IN]-()) <= $maxActors 
RETURN m.title, m.year, [(m)<-[:ACTED_IN]-(a) | a.name] AS actorNames;

Cobra_0-1661876690501.png

Regards,
Cobra

tard_gabriel
Ninja
Ninja
size((m)<-[:ACTED_IN]-())

I don't think it's possible to beat that as suggested by @Cobra 

Best I could do was 20,050 db hits haha, I believe adding the "0 < " is unnecessary right? For size to return < 0 wouldn't be possible? And it adds processing time (and somehow db hits?) so below is very very very barely faster 😉 hahah

MATCH (m:Movie)
WHERE size(()-[:ACTED_IN]->(m)) <= $maxActors
RETURN m.title, m.year, [(a)-[:ACTED_IN]->(m) | a.name]