Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-21-2022 09:13 AM - edited 07-29-2022 08:39 AM
For this week's challenge, let's create a recommendations sandbox at sandbox.neo4j.com.
This query returns the movie titles by a person who acted in the movies. We use the actorName parameter with the value "Clint Eastwood".
Your starting Cypher is
PROFILE
MATCH (a:Actor)-[:ACTED_IN]->(m:Movie)
WHERE a.name = $actor
RETURN m.title AS Movies
How can this query be improved?
Please post your solution below!
Solved! Go to Solution.
08-08-2022 09:31 AM
This query should be better:
MATCH (a:Person {name: $actor})-[:ACTED_IN]->(m)
RETURN m.title AS Movies;
Regards,
Cobra
08-07-2022 11:56 PM
Hello @TrevorS 😊
Here is my query:
:param actor => 'Clint Eastwood';
MATCH (a:Actor {name: $actor})
WITH a LIMIT 1
MATCH (a)-[:ACTED_IN]->(m)
RETURN m.title AS Movies;
Here is the screenshot:
The query performance can be improved by adding a UNIQUE CONSTRAINT or an INDEX without changing the query:
CREATE CONSTRAINT constraint_Actor_name FOR (n:Actor) REQUIRE n.name IS UNIQUE;
CREATE INDEX index_Actor_name FOR (n:Actor) ON (n.name);
Regards,
Cobra
08-08-2022 09:11 AM
@Cobra ,
You cannot create the constraint on this dataset. And we want a query that uses the database as is without adding an index.
Your query had an elapsed time of 7 ms.
There is a query with an elapsed time of 5 ms.
Elaine
08-08-2022 09:31 AM
This query should be better:
MATCH (a:Person {name: $actor})-[:ACTED_IN]->(m)
RETURN m.title AS Movies;
Regards,
Cobra
08-13-2022 02:52 PM
@TrevorS My solution is the best I think: 30 ms:
08-15-2022 05:36 AM
This query is not faster (even when I remove the update of the label).
A couple of things to note:
1. You do not want literals in your queries (except for testing a query). Use parameters.
2. Why are you setting the label? It is already an Actor?
All the sessions of the conference are now available online