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. The result of the query is shown in Figure
7-16
.
Figure 7-16.
Products Purchased by Friends and Matches User's Tags
Using
friendsPurchaseTagSimilarity
in
PurchaseService
, shown in Listing 7-55, the application provides the
userId to the query and uses the
FOLLOWS
,
MADE
, and
CONTAINS
relationships to return products purchases by users
being followed. The subsequent MATCH statement takes the USES and HAS directed relationship types to determine
the TAG connections the resulting products and the current user have in common.
Listing 7-55.
The
friendsPurchaseTagSimilarity
Method in
PurchaseService
public List<MappedProductUserPurchase> friendsPurchaseTagSimilarity(string userId)
{
return _graphClient.Cypher
.Match("(u:User { userId : {userId} } )-[:FOLLOWS]-(f)-[:MADE]->()-[:CONTAINS]->p")
.WithParam("userId", userId)
.With("u,p,f")
.Match("u-[:USES]->(t)<-[:HAS]-p")
.Return(() => Return.As<MappedProductUserPurchase>("{productId:p.productId,title:p.
title," +
"fullname:collect(f.firstname + ' ' + f.lastname),wordPhrase:t.wordPhrase,cfriends:
count(f)}"))
.OrderByDescending("count(f)")
.Results.ToList();
}