Database Reference
In-Depth Information
results=neo.execute_query(cypher, {:q => q} )
results["data"].map {|row| Hash[results["columns"].zip(row)] }
end
For almost all cases, it is recommended that you do not to use the graphId because it can be recycled when its
node is deleted. In this case, the productNodeId should be considered safe to use, because products would not be in
danger of being deleted but only removed from a Location relationship.
Once the product and distance have been set and the search is executed, the Location route tests to see if a
productNodeId property has been set. If so, the locations_within_distance_with_product method is called from the
Location class, which is shown in Listing 10-44.
Listing 10-44. The locations_within_distance_with_product Method in the Location Class
def locations_within_distance_with_product(neo,lq,productNodeId, mappedUserLocation)
cypher = " START n = node:geom({lq}), p=node({productNodeId}) " +
" MATCH n-[:HAS]->p " +
" RETURN n.locationId as locationId, n.address as address, n.city as city, " +
" n.state as state, n.zip as zip, n.name as name, n.lat as lat, n.lon as lon"
results = neo.execute_query(cypher, {:lq => lq, :productNodeId => productNodeId} )
r=results["data"].map {|row| Hash[*results["columns"].zip(row).flatten] }
r.each do |e|
d = distance [e["lat"].to_f,e["lon"].to_f],[mappedUserLocation["lat"].
to_f,mappedUserLocation["lon"].to_f]
e.merge!("distanceToLocation" => d.to_s + " Miles Away")
end
r
end
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 purchased by friends, the friends_purchase method is called from the
Purchase class, shown in Listing 10-46. The corresponding route is first shown in Listing 10-45.
Listing 10-45. Intent Route to Show Purchases Made by Friends
#purchases by friends
get '/intent' do
@title = "Products Purchased by Friends"
#get products purchased by Friends
@mappedProductUserPurchaseList =friends_purchase(neo,request.cookies[graphstoryUserAuthKey])
mustache :"graphs/intent/index"
end
 
Search WWH ::




Custom Search