Skip to content

Instantly share code, notes, and snippets.

@jexp
Last active July 11, 2023 21:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save jexp/2014efa6448b307c65e9 to your computer and use it in GitHub Desktop.
Save jexp/2014efa6448b307c65e9 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