Database Reference
In-Depth Information
Listing 9-39. The locations_within_distance Method in the Location Class
def locations_within_distance(self, graph_db, lq, mappedUserLocation,locationType):
query = neo4j.CypherQuery(graph_db, " START n = node:geom({lq}) " +
" WHERE n.type = {locationType} " +
" 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")
params = {"lq": lq, "locationType":locationType}
result = query.execute(**params)
for r in result:
# add the distance in miles
setattr(r, "distanceToLocation", self.distance(float(r.lon), float(r.lat),
float(mappedUserLocation["lon"]),
float(mappedUserLocation["lat"])))
Locations with Product
To search for products nearby,as shown in Figure 9-17 , the application makes use of an autosuggest AJAX request,
which ultimately calls the search method in the Product service class. The method, shown in Listing 9-40, returns
an array of objects to the product field in the search form and applies the selected product's productNodeId to the
subsequent location search.
Figure 9-17. Searching for Products in stock at Locations within a certain distance of the User location
Search WWH ::




Custom Search