Database Reference
In-Depth Information
$result = $query->getResultSet();
foreach($result as $row){
$row->distanceToLocation =
self::distance(floatval($mappedUserLocation["lat"]),
floatval($mappedUserLocation["lon"]),
floatval($row["lat"]),
floatval($row["lon"]),
"M") . " Miles away";
}
return $result;
}
Intent Graph Model
The last part of the graph model exploration considers all the other graphs in order to suggest products based on the
Purchase node type. The intent graph also considers the products, users, locations, and tags that are connected based
on a Purchase.
Products Purchased by Friends
To get all of the products that have been purchase by friends, the friendsPurchase method is called from Purchase
class, which is shown in Listing 8-45. The corresponding route is shown in Listing 8-44.
Listing 8-44. Intent Route to Show Purchases Made by Friends
// purchases by friends
$app->get('/intent', $isLoggedIn, function() use ($app){
$mappedProductUserPurchaseList = Purchase::friendsPurchase($_SESSION['username']);
$app->view()->setData(array(
'mappedProductUserPurchaseList' => $mappedProductUserPurchaseList,
'title' =>"Products Purchased by Friends"));
$app->render('graphs/intent/index.mustache');
})->name('intent');
The query shown in Listing 8-45 finds the users being followed by the current user and then matches those users
to a purchase that has been MADE which CONTAINS a product. The return value is a set of properties that identify the
product title, the name of the friend or friends, as well the number of friends who have bought the product. The result
is ordered by the number of friends who have purchased the product and then by product title, as shown in Figure 8-18 .
Listing 8-45. The friendsPurchase method in the Purchase Class
// products purchased by friends
public static function friendsPurchase($username){
$queryString =
" MATCH (u:User {username: {u} } )-[:FOLLOWS]-(f)-[:MADE]->()-[:CONTAINS]->p" .
" RETURN p.productId as productId, " .
" p.title as title, " .
" collect(f.firstname + ' ' + f.lastname) as fullname, " .
" null as wordPhrase, count(f) as cfriends " .
 
Search WWH ::




Custom Search