Database Reference
In-Depth Information
Products Purchased by Friends and Matches User's Tags
In this next instance, we want to determine products that have been purchased by friends but also have tags that are
used by the current user (Listing 8-47). The result of the query is shown in Figure 8-20 .
Listing 8-47. Product and Tag Similarity of the Current Users's Friends
// friends bought specific products. match these products to tags of the current user
$app->get('/intent/friendsPurchaseTagSimilarity', $isLoggedIn, function() use ($app){
$mappedProductUserPurchaseList = Purchase::friendsPurchaseTagSimilarity(
$_SESSION['username']);
$app->view()->setData(array(
'mappedProductUserPurchaseList' => $mappedProductUserPurchaseList,
'title' =>"Products Purchased by Friends and Matches User's Tags"));
$app->render('graphs/intent/index.mustache');
})->name('friendsPurchaseTagSimilarity');
Figure 8-20. Products Purchased by Friends and Matches User's Tags
Using friendsPurchaseTagSimilarity in Purchase service class, shown in Listing 8-48, the application provides
the userId to the query and uses the FOLLOWS , MADE, and CONTAINS relationships to return product purchases by users
being followed. The subsequent MATCH statement takes the USES and HAS directed relationship types to determine the
tag relationships the resulting products and the current user have in common.
Listing 8-48. The Method to Find Products Purchased by Friends and Matches Current User's Tags
// products purchased by friends that match the user's tags
public static function friendsPurchaseTagSimilarity($username){
$queryString =
" MATCH (u:User {username: {u} } )-[:FOLLOWS]-(f)-[:MADE]->()-[:CONTAINS]->p " .
" WITH u,p,f " .
" MATCH u-[:USES]->(t)<-[:HAS]-p " .
" RETURN p.productId as productId, " .
" p.title as title, " .
 
Search WWH ::




Custom Search