I'm very new to neo4j and to graph database in general. I'm prototyping an app, and I don't know how should i write these queries
I've this domain:
User Restaurant Review TypeOfFood
So a Restarurant have one or many TypeOfFood, the User leaves reviews about restaurants. The User have some preferred foods, matching the TypeOfFood a restaurant sell. Also Users are related to each other with the typically friend relationship.
Some of the queries I'm trying to write:
Give me all the restaurants that my friends have rated with 3 or more stars that make the kind of food I like (exclude those restaurants that I already reviewed)
Suggest me friends I may know (I guess this should be something like "all the friends that are friends of my friends but no yet mine, order by something)
If the query is not already in the Execution Plan Cache, the query is compiled into an execution plan in the Neo4j DBMS. The execution plan executes in the Neo4j DBMS to retrieve data. The Page Cache is used to hold the data in memory.
Cypher is Neo4j's graph query language that lets you retrieve data from the graph.
Cypher is a graph query language that is powerful and easy to use, and a unique feature of Neo4j.
Using Neo4j's Cypher query language you could write your queries like this:
Selecting the top-20 best rated restaurants, sorted by stars and number of reviews
start user=(users,name,'Nico')
match user-[:FRIEND]->friend-[r,:RATED]->restaurant-[:SERVES]->food,
user-[:LIKES]->food,user-[:RATED]->rated_by_me
where r.stars > 3
return restaurant.name, avg(r.stars), count(*)
order by avg(r.stars) desc, count(*) desc
limit 20
Friends of a Friend
start user=(users,name,'Nico')
match user-[:FRIEND]->friend->[:FRIEND]->foaf
return foaf, foaf.name
You can execute these cypher queries in the Neo4j Webadmin Console on your dataset, but also in the neo4j-shell, remotely via the Cypher-Rest-Plugin via Spring Data Graph.
There is also a screencast discussing similar queries in cypher.
You can also use Gremlin, Neo4j-Traversers or manual traversing via getRelationships
if you'd like.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With