Skip to content

Instantly share code, notes, and snippets.

@johnymontana
Created June 11, 2018 16:38
Show Gist options
  • Save johnymontana/d6cd18a1eb1fcaf030a90bab25ef16b0 to your computer and use it in GitHub Desktop.
Save johnymontana/d6cd18a1eb1fcaf030a90bab25ef16b0 to your computer and use it in GitHub Desktop.
import { Date } from "neo4j-driver/lib/v1/temporal-types";
fetchBusinesses = () => {
const { mapCenter, startDate, endDate } = this.state;
const session = this.driver.session();
session.run(`
MATCH (b:Business)<-[:REVIEWS]-(r:Review)
WHERE $start <= r.date <= $end
AND distance(b.location,
point({latitude: $lat, longitude: $lon})) < ( $radius * 1000)
OPTIONAL MATCH (b)-[:IN_CATEGORY]->(c:Category)
WITH r,b, COLLECT(c.name) AS categories
WITH COLLECT(DISTINCT b {.*, categories}) AS businesses,
COLLECT(DISTINCT r) AS reviews
UNWIND reviews AS r
WITH businesses, r.stars AS stars, COUNT(r) AS num
ORDER BY stars
WITH businesses,
COLLECT({stars: toString(stars), count:toFloat(num)})
AS starsData
RETURN businesses, starsData`,
{ lat: mapCenter.latitude, lon: mapCenter.longitude,
radius: mapCenter.radius,
start: new Date(
startDate.year(),
startDate.month() + 1,
startDate.date()),
end: new Date(
endDate.year(),
endDate.month() + 1,
endDate.date())
}
)
.then(result => {
console.log(result);
const record = result.records[0];
const businesses = record.get("businesses");
const starsData = record.get("starsData");
this.setState({
businesses,
starsData
});
session.close();
})
.catch(e => {
console.log(e);
session.close();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment