cypher - Neo4j: weighted relationships, how to reflect important relationships in query? -


i have data in relationships important others , weighted indicate it. example, have graph this:

  (city_a:city)-[:has{weight:10}]->(casino:event)   (city_a:city)-[:has{weight:1}]->(restaurant:event)   (city_a:city)-[:has{weight:30}]->(university:event)       (city_a:city)-[:has{weight:25}]->(library:event)     ......   (city_b:city)-[:has{weight:2}]->(casino:event)   (city_b:city)-[:has{weight:2}]->(restaurant:event)   (city_b:city)-[:has{weight:5}]->(university:event)       (city_b:city)-[:has{weight:10}]->(library:event)     ......   

and have input following

  input: {casino, restaurant, university} 

and should output

  output: city_a  

as answer since has relationships weighted more other cities.

(maybe graph model not right one, not think of also. advices welcomed).

so, how write cypher query case?

thanks in advance!

here's example graph based on description, 'city_c' thrown in cover case of city fewer desired input events:

merge (city_a:city{name:'city_a'}) merge (city_b:city{name:'city_b'}) merge (city_c:city{name:'city_c'})  merge (casino:event{name:'casino'}) merge (restaurant:event{name:'restaurant'}) merge (university:event{name:'university'}) merge (library:event{name:'library'})  merge (city_a)-[:has{weight:10}]->(casino) merge (city_a)-[:has{weight:1}]->(restaurant) merge (city_a)-[:has{weight:30}]->(university)     merge (city_a)-[:has{weight:25}]->(library)   merge (city_b)-[:has{weight:2}]->(casino) merge (city_b)-[:has{weight:2}]->(restaurant) merge (city_b)-[:has{weight:5}]->(university)     merge (city_b)-[:has{weight:10}]->(library)   merge (city_c)-[:has{weight:100}]->(university)  

we'll want index on :event(name) quick lookups input strings (you'll want index on :city(name), though won't needed or used particular query)

create index on :event(name) 

from can create query match input events cities events , order number of matching events per city , sum of ratings.

instead of with ... input you'd want parameterize query.

with ['casino', 'restaurant', 'university'] input match (e:event)<-[r:has]-(city:city) e.name in input city, count(r) eventcount, sum(r.weight) weightsum return city, eventcount, weightsum order eventcount desc, weightsum desc limit 1 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -