Ordering Search Results

Pearson similarity overview and problem statement

In this section you will improve the display of search results. When a user searches for businesses we want to order the results so that we show the most relevant results first. To do that, you will use the Pearson similarity metric.

Let’s look at the part of the application that you will enhance.

In the CodeSandbox Browser, you can select Business Search, and search for Pizza in the category Restaurants.


Instead of showing results in alphabetical order you will modify the application to show the most relevant businesses first.

Useful Resources


You will update the application to use this new information.

Instead of selecting the reviews for our businesses based on the opinions of users unrelated to user-name, we’ll show reviews written by similar users.

  1. In Neo4j Browser, perform the steps in Neo4j Browser guide section Search Results. (:play applied_graph_algorithms/03_search_results.html)

  2. In CodeSandbox, edit the Cypher query in src/exercises/exercise2.js to return businesses.

  3. Save this file.

  4. In the CodeSandbox Browser, select a user from the User Profile drop down. This will set this user for the search.

  5. Select Business Search, entering pizza for the search text and select Restaurant for the category. You should see a list of restaurants that are relevant to that user.

  6. Select a different user and then search for pizza restaurants. You should see a different set of restaurants.

This query should be in the context of the currently "logged in" user in the application. Since our simple application doesn’t have any authentication mechanism we fake this by choosing a user in the dropdown in the "User Profile" section of the application. The id of the currently logged in user will be available as a Cypher parameter userId in the query.

So for example, to find the currently logged in user:

MATCH (me:User {id: $userId})


If you get stuck, watch this video for a walk-through of the solution:

Ordering search results solution

Check your understanding

Question 1

Algorithm Understanding: Pearson Similarity

Which of the following are valid values that can be returned by the Pearson Similarity algorithm?

Select the correct answers.

  • 0.72

  • -3.41

  • 2.34

  • -0.52

Question 2

Running the algorithm in Neo4j

Which of the following are fields returned by the algo.similarity.pearson procedure?

Select the correct answers.

  • similarityPairs

  • relationships

  • p75

  • writeRelationshipType


You should now be able to:

  • Use the Pearson Similarity graph algorithm.