Search in sources :

Example 1 with ContainsAnyComparison

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

the class RestaurantIntegrationTest method shouldFilterByCollectionContaining.

@Test
public void shouldFilterByCollectionContaining() {
    Restaurant sfo = new Restaurant("San Francisco International Airport (SFO)", 72.4);
    sfo.getSpecialities().add("burger");
    sfo.getSpecialities().add("pizza");
    session.save(sfo);
    Restaurant kuroda = new Restaurant("Kuroda", 80.5);
    kuroda.getSpecialities().add("sushi");
    session.save(kuroda);
    Filter f1 = new Filter("specialities", new ContainsAnyComparison(Arrays.asList("burger")));
    Collection<Restaurant> burgers = session.loadAll(Restaurant.class, new Filters(f1));
    assertThat(burgers).hasSize(1);
    assertThat(burgers.iterator().next().getName()).isEqualTo("San Francisco International Airport (SFO)");
    Filter f2 = new Filter("specialities", new ContainsAnyComparison(Arrays.asList("burger", "sushi")));
    Collection<Restaurant> all = session.loadAll(Restaurant.class, new Filters(f2));
    assertThat(all).hasSize(2);
    Filter f3 = new Filter("specialities", new ContainsAnyComparison(Arrays.asList("sushi", "other")));
    Collection<Restaurant> sushi = session.loadAll(Restaurant.class, new Filters(f3));
    assertThat(sushi).hasSize(1);
}
Also used : Restaurant(org.neo4j.ogm.domain.restaurant.Restaurant) Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter) ContainsAnyComparison(org.neo4j.ogm.cypher.function.ContainsAnyComparison) Test(org.junit.Test)

Example 2 with ContainsAnyComparison

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

the class FilterTest method inCollectionFilterTest.

@Test
public void inCollectionFilterTest() {
    ContainsAnyComparison filterFunction = new ContainsAnyComparison("test");
    Filter filter = new Filter("property", filterFunction);
    assertThat(filter.toCypher("n", true)).isEqualTo("WHERE ANY(collectionFields IN $`property_0` WHERE collectionFields in n.`property`) ");
    assertThat(filter.parameters().get("property_0")).isEqualTo("test");
}
Also used : ContainsAnyComparison(org.neo4j.ogm.cypher.function.ContainsAnyComparison) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 ContainsAnyComparison (org.neo4j.ogm.cypher.function.ContainsAnyComparison)2 Filter (org.neo4j.ogm.cypher.Filter)1 Filters (org.neo4j.ogm.cypher.Filters)1 Restaurant (org.neo4j.ogm.domain.restaurant.Restaurant)1