Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions api/dao/people.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
Expand All @@ -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[]
# end::getSimilarPeople[]