Database Reference
In-Depth Information
Listing 12-47.
Product and Tag Similarity of the Current Users's Friends
@Action(value = "intent/friendsPurchaseTagSimilarity",results = {
@Result(name = "success", type = "mustache", location = "/mustache/html/graphs/
intent/index.html")
})
public String friendsPurchaseTagSimilarity() {
setTitle("Products Purchased by Friends and Matches User's Tags");
try {
graphStory.setMappedProductUserPurchaseList(
graphStoryDAO.getPurchaseDAO()
.friendsPurchaseTagSimilarity(
cookiesMap.get(GraphStoryConstants.graphstoryUserAuthKey)
));
graphStory.setUser(graphStoryDAO.getUserDAO()
.getByUserName(
cookiesMap.get(GraphStoryConstants.graphstoryUserAuthKey)
));
}
catch (Exception e) {
log.error(e);
}
return SUCCESS;
}
Using
friendsPurchaseTagSimilarity
in
PurchaseDAO
service class, shown in Listing 12-48, the application
provides the userId to the query and uses the
FOLLOWS
,
MADE
and the
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 12-48.
The Method to Find Products Purchased by Friends and Matches Current User's Tags
public List<MappedProductUserPurchase> friendsPurchaseTagSimilarity(String username) {
try {
ResultSet rs = cypher.resultSetQuery(
"MATCH (u:User { username : {1} } )-[:FOLLOWS]-(f)-[:MADE]->()-[:CONTAINS]->p " +
" WITH u,p,f " +
" MATCH u-[:USES]->(t)<-[:HAS]-p " +
" RETURN p.productId as productId, " +
" p.title as title, " +
" collect(f.firstname + ' ' + f.lastname) as fullname, " +
" t.wordPhrase as wordPhrase, " +
" count(f) as cfriends " +
" ORDER BY cfriends desc, p.title ",
map("1", username));