diff --git a/api/dao/people.py b/api/dao/people.py index ef9841c..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: size((p)-[:ACTED_IN]->()), - directedCount: size((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: size((p)-[:ACTED_IN]->()), - directedCount: size((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 @@ -96,4 +97,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[]