Search in sources :

Example 1 with DistanceComparison

use of org.neo4j.ogm.cypher.function.DistanceComparison in project neo4j-ogm by neo4j.

the class RestaurantIntegrationTest method shouldQueryByDistanceUsingFilter.

@Test
public void shouldQueryByDistanceUsingFilter() {
    Restaurant restaurant = new Restaurant("San Francisco International Airport (SFO)", new Location(37.61649, -122.38681), 94128);
    session.save(restaurant);
    session.clear();
    Filter filter = new Filter(new DistanceComparison(new DistanceFromPoint(37.61649, -122.38681, 1000 * 1000.0)), ComparisonOperator.LESS_THAN);
    Collection<Restaurant> found = session.loadAll(Restaurant.class, filter);
    assertThat(found).isNotNull();
    assertThat(found.size() >= 1).isTrue();
}
Also used : Restaurant(org.neo4j.ogm.domain.restaurant.Restaurant) DistanceComparison(org.neo4j.ogm.cypher.function.DistanceComparison) DistanceFromPoint(org.neo4j.ogm.cypher.function.DistanceFromPoint) Filter(org.neo4j.ogm.cypher.Filter) Location(org.neo4j.ogm.domain.restaurant.Location) Test(org.junit.Test)

Example 2 with DistanceComparison

use of org.neo4j.ogm.cypher.function.DistanceComparison in project neo4j-ogm by neo4j.

the class NodeQueryStatementsTest method testFindByDistance.

@Test
public void testFindByDistance() {
    DistanceComparison function = new DistanceComparison(new DistanceFromPoint(37.4d, 112.9d, 1000.0d));
    Filters filters = new Filters().add(new Filter(function, ComparisonOperator.EQUALS));
    String statement = queryStatements.findByType("Restaurant", filters, 4).getStatement();
    assertThat(statement).isEqualTo("MATCH (n:`Restaurant`) WHERE distance(point({latitude: n.latitude, longitude: n.longitude}),point({latitude: $lat, longitude: $lon})) = $distance WITH n MATCH p=(n)-[*0..4]-(m) RETURN p, ID(n)");
}
Also used : DistanceComparison(org.neo4j.ogm.cypher.function.DistanceComparison) DistanceFromPoint(org.neo4j.ogm.cypher.function.DistanceFromPoint) Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter) Test(org.junit.Test)

Example 3 with DistanceComparison

use of org.neo4j.ogm.cypher.function.DistanceComparison in project neo4j-ogm by neo4j.

the class FilterTest method toCypher_function.

@Test
public void toCypher_function() {
    DistanceComparison function = new DistanceComparison(new DistanceFromPoint(37.4, 112.1, 1000.0));
    Filter filter = new Filter(function, ComparisonOperator.LESS_THAN);
    filter.setBooleanOperator(BooleanOperator.AND);
    filter.setNegated(true);
    assertThat(filter.toCypher("n", true)).isEqualTo("WHERE NOT(distance(point({latitude: n.latitude, longitude: n.longitude}),point({latitude: $lat, longitude: $lon})) < $distance ) ");
    Map<String, Object> parameters = filter.parameters();
    assertThat(parameters).containsEntry("lat", 37.4);
    assertThat(parameters).containsEntry("lon", 112.1);
    assertThat(parameters).containsEntry("distance", 1000.0);
}
Also used : DistanceComparison(org.neo4j.ogm.cypher.function.DistanceComparison) DistanceFromPoint(org.neo4j.ogm.cypher.function.DistanceFromPoint) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 DistanceComparison (org.neo4j.ogm.cypher.function.DistanceComparison)3 DistanceFromPoint (org.neo4j.ogm.cypher.function.DistanceFromPoint)3 Filter (org.neo4j.ogm.cypher.Filter)2 Filters (org.neo4j.ogm.cypher.Filters)1 Location (org.neo4j.ogm.domain.restaurant.Location)1 Restaurant (org.neo4j.ogm.domain.restaurant.Restaurant)1