Restaurant Recommendations

Restaurant Recommendations: Introduction

restaurant recommendation model

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 that serve cuisines and are located in a city.

The domain diagram was created with the Arrows tool.

Setup: Creating Friends, Restaurants, Cities, and Cuisines

We will create a small example graph of people with cuisines they like and the restaurants serving those cuisines. Our people are in the same social circle (friend relationships), so we can create recommendations of cuisines and restaurants others will like based on their social connections and their preferences.

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),
       (zam:Restaurant {name:"Zushi Zam"})-[:SERVES]->(sushi),(zam)-[:LOCATED_IN]->(nyc),

Setup: Philip’s Friends

First, let’s some of our graph data and find who is friends with Philip.

MATCH (philip:Person {name:'Philip'})-[:IS_FRIEND_OF]-(person)

We should see 3 friends of Philip in our graph - Andreas, Michael, and Emil.

Restaurants in NYC and their cusines

Now let’s look at restaurants and the cities where they are located with the cuisines they serve.

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

This query should show us nodes and relationships for the City of New York, 2 restaurants LOCATED_IN that city, and that each restaurant SERVES the Cuisine of sushi.

Graph Search Recommendation

sushi restaurants nyc

Now that we have an idea what our data looks like, we can start recommending things based on the relationships connecting our people, location, cuisines, and restaurants.

We want to make a recommendation for Philip by answering the following question:

Find Sushi Restaurants in New York that Philip’s friends like.

Recommendation criteria

To answer this question, we need to find our starting point - Philip needs the recommendation, so his node is where we start our search in the graph. Now we need to determine which parts of the graph to search using the following criteria from the question:

  • Find Philip and his friends

  • Find Restaurants that are located in New York

  • Find Restaurants that serve the cuisine sushi

  • Find Restaurants that Philip’s friends like

Recommendation query

With those criteria, we construct this query:

MATCH (philip:Person {name: 'Philip'}),
      (restaurant:Restaurant)-[:LOCATED_IN]->(:City {name: 'New York'}),
      (restaurant)-[:SERVES]->(:Cuisine {name: 'Sushi'}),
RETURN as restaurantName, collect( AS recommendedBy, count(*) AS numberOfRecommendations
ORDER BY numberOfRecommendations DESC

This tells us that 2 of Philip’s friends recommend iSushi restaurant for sushi, and 1 of his friends recommends Zushi Zam restaurant for sushi.

More on recommendations

Larger graphs and deeper relationship paths can add complexity and power to recommendation engines. This example shows the beginning steps and logic for building these systems using the relationships in the network to recommend products, hobbies, services, similarities, and more.