// This script php implements // find all artists listened by a user’s friend but not the user, order them by the // number of friends listening to them, recommend the top 5 // Include library of functions include "functions.php"; // connection to neo4j require 'vendor/autoload.php'; $client = new Everyman\Neo4j\Client('localhost', 7474); printHeader(); printSearchForm($uid); echo "<b>User: {$uid} - All Artist Listened by my friends</b><br><br>"; $queryString = "MATCH (u:user {id:{$uid}})-[:ADD_FRIEND_TO]-(:user)-[listen: WEIGHT]-(a:artist)\r\nWHERE NOT (u)-[:WEIGHT]-(a)\r\nWITH a, count(u) as count\r\nRETURN a\r\nORDER BY count desc LIMIT 5"; $query = new Everyman\Neo4j\Cypher\Query($client, $queryString); $result = $query->getResultSet(); foreach ($result as $row) { $artist = $client->getNode($row['x']->getId()); $artistId = $artist->getProperty('id'); $artistName = $artist->getProperty('name'); echo "Artist Name: " . $artistName . "</br>"; printArtistInfo($artistId); ?> <form action="listen.php" method="post"> <input type="hidden" name="action" value="addlisten"> <input type="hidden" name="userId" value="<?php echo $uid; ?> "> <input type="hidden" name="artistId" value="<?php echo $artistId; ?> ">
break; case 1: // Do nothing break; case 2: // create the relation add_friend_to $id1 = (int) trim($atributes[0]); $id2 = (int) trim($atributes[1]); //echo "Lee ". $id1 . " a friend of ". $id2 ."\n"; $userId1 = 0; $userId2 = 0; $queryString = "match (n:user {id: {id}}) return n"; $query = new Everyman\Neo4j\Cypher\Query($client, $queryString, array('id' => $id1)); $result = $query->getResultSet(); foreach ($result as $row) { $user1 = $client->getNode($row['x']->getId()); $userId1 = $user1->getProperty('id'); //echo "user " . $id1 ." founded\n"; } $queryString = "match (n:user {id: {id}}) return n"; $query = new Everyman\Neo4j\Cypher\Query($client, $queryString, array('id' => $id2)); $result = $query->getResultSet(); foreach ($result as $row) { $user2 = $client->getNode($row['x']->getId()); $userId2 = $user2->getProperty('id'); //echo "user " . $id2 ." founded\n"; } //echo "Crea relacion " . $userId1 . " -> " . $userId2 ."\n\n"; $user1->relateTo($user2, 'ADD_FRIEND_TO')->save(); break; default: