From ebaaad143c2769c068983f54ffc40f0ef3edfe4b Mon Sep 17 00:00:00 2001 From: Amaan Sheikh <100550299+amaan784@users.noreply.github.com> Date: Tue, 12 Mar 2024 14:36:11 -0400 Subject: [PATCH 1/2] Update cypher query in find_by_id() and get_similar_people() in people.py the size() function no longer works. Updating as per the correct cypher query mentioned in the course. --- api/dao/people.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/api/dao/people.py b/api/dao/people.py index ef9841c..e5d87d7 100644 --- a/api/dao/people.py +++ b/api/dao/people.py @@ -57,8 +57,8 @@ def get_person(tx, id): MATCH (p:Person {tmdbId: $id}) RETURN p { .*, - actedCount: size((p)-[:ACTED_IN]->()), - directedCount: size((p)-[:DIRECTED]->()) + actedCount: count {(p)-[:ACTED_IN]->()}, + directedCount: count {(p)-[:DIRECTED]->()} } AS person """, id=id).single() @@ -83,8 +83,8 @@ def get_similar_people(tx, id, skip, limit): MATCH (:Person {tmdbId: $id})-[:ACTED_IN|DIRECTED]->(m)<-[r:ACTED_IN|DIRECTED]-(p) RETURN p { .*, - actedCount: size((p)-[:ACTED_IN]->()), - directedCount: size((p)-[:DIRECTED]->()), + actedCount: count {(p)-[:ACTED_IN]->()}, + directedCount: count {(p)-[:DIRECTED]->()}, inCommon: collect(m {.tmdbId, .title, type: type(r)}) } AS person ORDER BY size(person.inCommon) DESC @@ -96,4 +96,4 @@ def get_similar_people(tx, id, skip, limit): with self.driver.session() as session: return session.execute_read(get_similar_people, id, skip, limit) - # end::getSimilarPeople[] \ No newline at end of file + # end::getSimilarPeople[] From 6ca97a959591a056e735ff566ae63e1f9160169b Mon Sep 17 00:00:00 2001 From: Amaan Sheikh Date: Tue, 12 Mar 2024 18:48:27 +0000 Subject: [PATCH 2/2] Update cypher query in find_by_id() and get_similar_people() in people.py --- api/dao/people.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/api/dao/people.py b/api/dao/people.py index e5d87d7..f2a1f75 100644 --- a/api/dao/people.py +++ b/api/dao/people.py @@ -56,9 +56,9 @@ def get_person(tx, id): row = tx.run(""" MATCH (p:Person {tmdbId: $id}) RETURN p { - .*, - actedCount: count {(p)-[:ACTED_IN]->()}, - directedCount: count {(p)-[:DIRECTED]->()} + .*, + actedCount: count {(p)-[:ACTED_IN]->()}, + directedCount: count {(p)-[:DIRECTED]->()} } AS person """, id=id).single() @@ -81,11 +81,12 @@ def get_similar_people(self, id, limit = 6, skip = 0): def get_similar_people(tx, id, skip, limit): result = tx.run(""" MATCH (:Person {tmdbId: $id})-[:ACTED_IN|DIRECTED]->(m)<-[r:ACTED_IN|DIRECTED]-(p) + WITH p, collect(m {.tmdbId, .title, type: type(r)}) AS inCommon RETURN p { - .*, - actedCount: count {(p)-[:ACTED_IN]->()}, - directedCount: count {(p)-[:DIRECTED]->()}, - inCommon: collect(m {.tmdbId, .title, type: type(r)}) + .*, + actedCount: count {(p)-[:ACTED_IN]->()}, + directedCount: count {(p)-[:DIRECTED]->()}, + inCommon: inCommon } AS person ORDER BY size(person.inCommon) DESC SKIP $skip