We want to demonstrate how easy it is to model a domain as a graph and answer questions in almost natural language.
Graph Based Search and Discovery is prominent a use-case for graph databases like Neo4j.
Here we use a Domain of restaurants which serve cuisines and are located in a City.
The domain diagram was created with the Arrows tool
CREATE (philip:Person {name:"Philip"})-[:IS_FRIEND_OF]->(emil:Person {name:"Emil"}),
(philip)-[:IS_FRIEND_OF]->(michael:Person {name:"Michael"}),
(philip)-[:IS_FRIEND_OF]->(andreas:Person {name:"Andreas"})
create (sushi:Cuisine {name:"Sushi"}), (nyc:City {name:"New York"}),
(iSushi:Restaurant {name:"iSushi"})-[:SERVES]->(sushi),(iSushi)-[:LOCATED_IN]->(nyc),
(michael)-[:LIKES]->(iSushi),
(andreas)-[:LIKES]->(iSushi),
(zam:Restaurant {name:"Zushi Zam"})-[:SERVES]->(sushi),(zam)-[:LOCATED_IN]->(nyc),
(andreas)-[:LIKES]->(zam)
MATCH (nyc:City {name:"New York"})<-[:LOCATED_IN]-(restaurant)-[:SERVES]->(cusine)
RETURN nyc, restaurant, cusine
We want to answer the following question
"" Find Sushi Restaurants in New York that my friends like. ""
To satisfy this question, we have to know who’s asking: Philip and he’s asking for 4 connected facts
-
People that are friends of Philip
-
Restaurants located in New York
-
Restaurants that server Sushi
-
Restaurants that his Friends like
MATCH (philip:Person {name:"Philip"}),
(philip)-[:IS_FRIEND_OF]-(friend),
(restaurant:Restaurant)-[:LOCATED_IN]->(:City {name:"New York"}),
(restaurant)-[:SERVES]->(:Cuisine {name:"Sushi"}),
(friend)-[:LIKES]->(restaurant)
RETURN restaurant.name, collect(friend.name) as likers, count(*) as occurence
ORDER BY occurence DESC