Search in sources :

Example 1 with GeoDistanceOrder

use of org.springframework.data.elasticsearch.core.query.GeoDistanceOrder in project spring-data-elasticsearch by spring-projects.

the class CustomMethodRepositoryIntegrationTests method shouldUseGeoSortParameter.

// DATAES-734
@Test
void shouldUseGeoSortParameter() {
    GeoPoint munich = new GeoPoint(48.137154, 11.5761247);
    GeoPoint berlin = new GeoPoint(52.520008, 13.404954);
    GeoPoint vienna = new GeoPoint(48.20849, 16.37208);
    GeoPoint oslo = new GeoPoint(59.9127, 10.7461);
    List<SampleEntity> entities = new ArrayList<>();
    SampleEntity entity1 = new SampleEntity();
    entity1.setId("berlin");
    entity1.setLocation(berlin);
    entities.add(entity1);
    SampleEntity entity2 = new SampleEntity();
    entity2.setId("vienna");
    entity2.setLocation(vienna);
    entities.add(entity2);
    SampleEntity entity3 = new SampleEntity();
    entity3.setId("oslo");
    entity3.setLocation(oslo);
    entities.add(entity3);
    repository.saveAll(entities);
    SearchHits<SampleEntity> searchHits = repository.searchBy(Sort.by(new GeoDistanceOrder("location", munich)));
    assertThat(searchHits.getTotalHits()).isEqualTo(3);
    assertThat(searchHits.getSearchHit(0).getId()).isEqualTo("vienna");
    assertThat(searchHits.getSearchHit(1).getId()).isEqualTo("berlin");
    assertThat(searchHits.getSearchHit(2).getId()).isEqualTo("oslo");
}
Also used : GeoPoint(org.springframework.data.elasticsearch.core.geo.GeoPoint) GeoDistanceOrder(org.springframework.data.elasticsearch.core.query.GeoDistanceOrder) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Aggregations

ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1 GeoPoint (org.springframework.data.elasticsearch.core.geo.GeoPoint)1 GeoDistanceOrder (org.springframework.data.elasticsearch.core.query.GeoDistanceOrder)1 SpringIntegrationTest (org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)1