Search in sources :

Example 1 with GeoPoint

use of org.springframework.data.elasticsearch.core.geo.GeoPoint in project spring-data-elasticsearch by spring-projects.

the class CustomMethodRepositoryIntegrationTests method shouldCountCustomMethodWithNearPointAndDistance.

// DATAES-106
@Test
public void shouldCountCustomMethodWithNearPointAndDistance() {
    // given
    String documentId = nextIdAsString();
    SampleEntity sampleEntity = new SampleEntity();
    sampleEntity.setId(documentId);
    sampleEntity.setType("test");
    sampleEntity.setRate(10);
    sampleEntity.setMessage("foo");
    sampleEntity.setLocation(new GeoPoint(45.7806d, 3.0875d));
    repository.save(sampleEntity);
    documentId = nextIdAsString();
    SampleEntity sampleEntity2 = new SampleEntity();
    sampleEntity2.setId(documentId);
    sampleEntity2.setType("test");
    sampleEntity2.setRate(10);
    sampleEntity2.setMessage("foo");
    sampleEntity2.setLocation(new GeoPoint(30.7806d, 0.0875d));
    repository.save(sampleEntity2);
    // when
    long count = repository.countByLocationNear(new Point(3.0875d, 45.7806d), new Distance(2, Metrics.KILOMETERS));
    // then
    assertThat(count).isEqualTo(1L);
}
Also used : GeoPoint(org.springframework.data.elasticsearch.core.geo.GeoPoint) Point(org.springframework.data.geo.Point) GeoPoint(org.springframework.data.elasticsearch.core.geo.GeoPoint) Distance(org.springframework.data.geo.Distance) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 2 with GeoPoint

use of org.springframework.data.elasticsearch.core.geo.GeoPoint in project spring-data-elasticsearch by spring-projects.

the class CustomMethodRepositoryIntegrationTests method shouldExecuteCustomMethodWithWithinGeoPoint.

@Test
public void shouldExecuteCustomMethodWithWithinGeoPoint() {
    // given
    String documentId = nextIdAsString();
    SampleEntity sampleEntity = new SampleEntity();
    sampleEntity.setId(documentId);
    sampleEntity.setType("test");
    sampleEntity.setRate(10);
    sampleEntity.setMessage("foo");
    sampleEntity.setLocation(new GeoPoint(45.7806d, 3.0875d));
    repository.save(sampleEntity);
    // when
    Page<SampleEntity> page = repository.findByLocationWithin(new GeoPoint(45.7806d, 3.0875d), "2km", PageRequest.of(0, 10));
    // then
    assertThat(page).isNotNull();
    assertThat(page.getTotalElements()).isEqualTo(1L);
}
Also used : GeoPoint(org.springframework.data.elasticsearch.core.geo.GeoPoint) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 3 with GeoPoint

use of org.springframework.data.elasticsearch.core.geo.GeoPoint in project spring-data-elasticsearch by spring-projects.

the class CustomMethodRepositoryIntegrationTests method shouldExecuteCustomMethodWithWithinPoint.

@Test
public void shouldExecuteCustomMethodWithWithinPoint() {
    // given
    String documentId = nextIdAsString();
    SampleEntity sampleEntity = new SampleEntity();
    sampleEntity.setId(documentId);
    sampleEntity.setType("test");
    sampleEntity.setRate(10);
    sampleEntity.setMessage("foo");
    sampleEntity.setLocation(new GeoPoint(45.7806d, 3.0875d));
    repository.save(sampleEntity);
    // when
    Page<SampleEntity> page = repository.findByLocationWithin(new Point(3.0875d, 45.7806d), new Distance(2, Metrics.KILOMETERS), PageRequest.of(0, 10));
    // then
    assertThat(page).isNotNull();
    assertThat(page.getTotalElements()).isEqualTo(1L);
}
Also used : GeoPoint(org.springframework.data.elasticsearch.core.geo.GeoPoint) Point(org.springframework.data.geo.Point) GeoPoint(org.springframework.data.elasticsearch.core.geo.GeoPoint) Distance(org.springframework.data.geo.Distance) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 4 with GeoPoint

use of org.springframework.data.elasticsearch.core.geo.GeoPoint 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)

Example 5 with GeoPoint

use of org.springframework.data.elasticsearch.core.geo.GeoPoint in project spring-data-elasticsearch by spring-projects.

the class CustomMethodRepositoryIntegrationTests method shouldCountCustomMethodWithWithinPoint.

// DATAES-106
@Test
public void shouldCountCustomMethodWithWithinPoint() {
    // given
    String documentId = nextIdAsString();
    SampleEntity sampleEntity = new SampleEntity();
    sampleEntity.setId(documentId);
    sampleEntity.setType("test");
    sampleEntity.setRate(10);
    sampleEntity.setMessage("foo");
    sampleEntity.setLocation(new GeoPoint(45.7806d, 3.0875d));
    repository.save(sampleEntity);
    documentId = nextIdAsString();
    SampleEntity sampleEntity2 = new SampleEntity();
    sampleEntity2.setId(documentId);
    sampleEntity2.setType("test");
    sampleEntity2.setRate(10);
    sampleEntity2.setMessage("foo");
    sampleEntity2.setLocation(new GeoPoint(30.7806d, 0.0875d));
    repository.save(sampleEntity2);
    // when
    long count = repository.countByLocationWithin(new Point(3.0875d, 45.7806d), new Distance(2, Metrics.KILOMETERS));
    // then
    assertThat(count).isEqualTo(1L);
}
Also used : GeoPoint(org.springframework.data.elasticsearch.core.geo.GeoPoint) Point(org.springframework.data.geo.Point) GeoPoint(org.springframework.data.elasticsearch.core.geo.GeoPoint) Distance(org.springframework.data.geo.Distance) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Aggregations

GeoPoint (org.springframework.data.elasticsearch.core.geo.GeoPoint)18 Test (org.junit.jupiter.api.Test)15 SpringIntegrationTest (org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)12 Point (org.springframework.data.geo.Point)8 Distance (org.springframework.data.geo.Distance)5 Document (org.springframework.data.elasticsearch.core.document.Document)2 GeoBox (org.springframework.data.elasticsearch.core.geo.GeoBox)2 GeoJsonLineString (org.springframework.data.elasticsearch.core.geo.GeoJsonLineString)2 GeoJsonMultiLineString (org.springframework.data.elasticsearch.core.geo.GeoJsonMultiLineString)2 Box (org.springframework.data.geo.Box)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 GeoDistance (org.elasticsearch.common.geo.GeoDistance)1 GeoDistanceQueryBuilder (org.elasticsearch.index.query.GeoDistanceQueryBuilder)1 Sort (org.springframework.data.domain.Sort)1 SearchHits (org.springframework.data.elasticsearch.core.SearchHits)1 SearchPage (org.springframework.data.elasticsearch.core.SearchPage)1 Criteria (org.springframework.data.elasticsearch.core.query.Criteria)1 CriteriaQuery (org.springframework.data.elasticsearch.core.query.CriteriaQuery)1 GeoDistanceOrder (org.springframework.data.elasticsearch.core.query.GeoDistanceOrder)1