cypher - Creating Relationship on the fly for Neo4j -
i'm quite new in neo4j
, excited learn. using movie database , trying solve issue need create relationship between actor based on movie acts on together.
for example, harrison ford , alec guiness acts on same 4 movies. harisson ford total movie 34 movies , alec guiness total movie 16 movies.
i create relationship on fly say:
"harrison ford"-[:same_movie{weight: 0.12 }]->"alec guiness" "alec guiness"-[:same_movie{weight: 0.25 }]->"harrison ford"
i stuck @ getting calculation , alias, appreciate if can help.
match (a:actor{name:"alec guinness"})-[x:acts_in]->(:movie)<-[y:acts_in]-(b:actor{name:"harrison ford"}) return {start: a.name, rel: count(x), end : b.name}
ps: creating relationship physically not option in real case take lot of space.
thanks.
since need counts of movies in common total movies both actors have acted in, can try this
match (a:actor{name:"alec guinness"})-[:acted_in]->(m:movie)<-[:acted_in]-(b:person{name:"harrison ford"}) a,b,count(m) common, size(a-[:acted_in]->()) totala, size(b-[:acted_in]->()) totalb merge (a)-[:same_movie {weight: formula}]-(b)
replace formula
calculation using common
,totala
, totalb
make sure have index on name
property of actor
label.
update
instead of creating relationship, calculate require , sort before returning/further matching
match (a:actor)-[:acted_in]->(m:movie)<-[:acted_in]-(b:person) a,b,count(m) common, size(a-[:acted_in]->()) totala, size(b-[:acted_in]->()) totalb a,b,<formula using common,totala,totalb> weight order weight return a,b
Comments
Post a Comment