Search in sources :

Example 11 with GeoPoint

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

the class CriteriaFilterProcessor method twoParameterBBox.

private void twoParameterBBox(GeoBoundingBoxQueryBuilder filter, Object[] values) {
    Assert.isTrue(isType(values, GeoPoint.class) || isType(values, String.class), " both elements of boundedBy filter must be type of GeoPoint or text(format lat,lon or geohash)");
    if (values[0] instanceof GeoPoint) {
        GeoPoint topLeft = (GeoPoint) values[0];
        GeoPoint bottomRight = (GeoPoint) values[1];
        filter.setCorners(topLeft.getLat(), topLeft.getLon(), bottomRight.getLat(), bottomRight.getLon());
    } else {
        String topLeft = (String) values[0];
        String bottomRight = (String) values[1];
        filter.setCorners(topLeft, bottomRight);
    }
}
Also used : GeoPoint(org.springframework.data.elasticsearch.core.geo.GeoPoint)

Example 12 with GeoPoint

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

the class RequestFactoryTests method shouldBuildSearchWithGeoSortSort.

@Test
// FPI-734
void shouldBuildSearchWithGeoSortSort() throws JSONException {
    CriteriaQuery query = new CriteriaQuery(new Criteria("lastName").is("Smith"));
    Sort sort = Sort.by(new GeoDistanceOrder("location", new GeoPoint(49.0, 8.4)));
    query.addSort(sort);
    converter.updateQuery(query, Person.class);
    String expected = // 
    '{' + // 
    "  \"query\": {" + // 
    "    \"bool\": {" + // 
    "      \"must\": [" + // 
    "        {" + // 
    "          \"query_string\": {" + // 
    "            \"query\": \"Smith\"," + // 
    "            \"fields\": [" + // 
    "              \"last-name^1.0\"" + // 
    "            ]" + // 
    "          }" + // 
    "        }" + // 
    "      ]" + // 
    "    }" + // 
    "  }," + // 
    "  \"sort\": [" + // 
    "    {" + // 
    "      \"_geo_distance\": {" + // 
    "        \"current-location\": [" + // 
    "          {" + // 
    "            \"lat\": 49.0," + // 
    "            \"lon\": 8.4" + // 
    "          }" + // 
    "        ]," + // 
    "        \"unit\": \"m\"," + // 
    "        \"distance_type\": \"arc\"," + // 
    "        \"order\": \"asc\"," + // 
    "        \"mode\": \"min\"," + // 
    "        \"ignore_unmapped\": false" + // 
    "      }" + // 
    "    }" + // 
    "  ]" + '}';
    String searchRequest = requestFactory.searchRequest(query, Person.class, IndexCoordinates.of("persons")).source().toString();
    assertEquals(expected, searchRequest, false);
}
Also used : GeoPoint(org.springframework.data.elasticsearch.core.geo.GeoPoint) Sort(org.springframework.data.domain.Sort) Test(org.junit.jupiter.api.Test)

Example 13 with GeoPoint

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

the class CustomMethodRepositoryIntegrationTests method shouldExecuteCustomMethodWithNearBox.

@Test
public void shouldExecuteCustomMethodWithNearBox() {
    // 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("test2");
    sampleEntity2.setRate(10);
    sampleEntity2.setMessage("foo");
    sampleEntity2.setLocation(new GeoPoint(30.7806d, 0.0875d));
    repository.save(sampleEntity2);
    // when
    Page<SampleEntity> pageAll = repository.findAll(PageRequest.of(0, 10));
    // then
    assertThat(pageAll).isNotNull();
    assertThat(pageAll.getTotalElements()).isEqualTo(2L);
    // when
    Page<SampleEntity> page = repository.findByLocationNear(new Box(new Point(3d, 46d), new Point(4d, 45d)), PageRequest.of(0, 10));
    // then
    assertThat(page).isNotNull();
    assertThat(page.getTotalElements()).isEqualTo(1L);
}
Also used : GeoPoint(org.springframework.data.elasticsearch.core.geo.GeoPoint) GeoBox(org.springframework.data.elasticsearch.core.geo.GeoBox) Box(org.springframework.data.geo.Box) Point(org.springframework.data.geo.Point) GeoPoint(org.springframework.data.elasticsearch.core.geo.GeoPoint) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 14 with GeoPoint

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

the class CustomMethodRepositoryIntegrationTests method shouldExecuteCustomMethodWithGeoPoint.

@Test
public void shouldExecuteCustomMethodWithGeoPoint() {
    // 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.findByLocation(new GeoPoint(45.7806d, 3.0875d), 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 15 with GeoPoint

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

the class CustomMethodRepositoryIntegrationTests method shouldCountCustomMethodWithWithinGeoPoint.

// DATAES-106
@Test
public void shouldCountCustomMethodWithWithinGeoPoint() {
    // 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 GeoPoint(45.7806d, 3.0875d), "2km");
    // then
    assertThat(count).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)

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