Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save replaid/7963f20df0fbbdd42be567e0741a1759 to your computer and use it in GitHub Desktop.
Save replaid/7963f20df0fbbdd42be567e0741a1759 to your computer and use it in GitHub Desktop.
Restaurant Recommendation GraphGist

Restaurant Recommendations

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.

sushi restaurants nyc

The domain diagram was created with the Arrows tool

Setup: Creating Friends, Restaurants in Cities and their Cusines

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)

Philips Friends

MATCH (philip:Person {name:"Philip"})-[:IS_FRIEND_OF]-(person)
RETURn person.name

Restaurants in NYC and their cusines

MATCH (nyc:City {name:"New York"})<-[:LOCATED_IN]-(restaurant)-[:SERVES]->(cusine)
RETURN nyc, restaurant, cusine

Graph Search Recommendation

We want to answer the following question

"" Find Sushi Restaurants in New York that my friends like. ""

sushi restaurants nyc

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment