Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-3676 Document mapping of geo-points
- Loading branch information
Showing
11 changed files
with
870 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
.../test/java/org/hibernate/search/documentation/mapper/orm/spatial/genericfield/Author.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.documentation.mapper.orm.spatial.genericfield; | ||
|
||
import javax.persistence.Embedded; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
|
||
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField; | ||
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField; | ||
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; | ||
|
||
//tag::include[] | ||
@Entity | ||
@Indexed | ||
public class Author { | ||
|
||
@Id | ||
@GeneratedValue | ||
private Integer id; | ||
|
||
@FullTextField(analyzer = "name") | ||
private String name; | ||
|
||
@Embedded | ||
@GenericField // <3> | ||
private MyCoordinates placeOfBirth; | ||
|
||
public Author() { | ||
} | ||
|
||
// Getters and setters | ||
// ... | ||
|
||
//tag::getters-setters[] | ||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public MyCoordinates getPlaceOfBirth() { | ||
return placeOfBirth; | ||
} | ||
|
||
public void setPlaceOfBirth(MyCoordinates placeOfBirth) { | ||
this.placeOfBirth = placeOfBirth; | ||
} | ||
//end::getters-setters[] | ||
} | ||
//end::include[] |
78 changes: 78 additions & 0 deletions
78
...ibernate/search/documentation/mapper/orm/spatial/genericfield/GeoPointGenericFieldIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.documentation.mapper.orm.spatial.genericfield; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.List; | ||
import javax.persistence.EntityManagerFactory; | ||
|
||
import org.hibernate.search.documentation.testsupport.BackendConfigurations; | ||
import org.hibernate.search.engine.spatial.DistanceUnit; | ||
import org.hibernate.search.mapper.orm.Search; | ||
import org.hibernate.search.mapper.orm.automaticindexing.AutomaticIndexingSynchronizationStrategyName; | ||
import org.hibernate.search.mapper.orm.cfg.HibernateOrmMapperSettings; | ||
import org.hibernate.search.mapper.orm.session.SearchSession; | ||
import org.hibernate.search.util.impl.integrationtest.common.rule.BackendConfiguration; | ||
import org.hibernate.search.util.impl.integrationtest.orm.OrmSetupHelper; | ||
import org.hibernate.search.util.impl.integrationtest.orm.OrmUtils; | ||
|
||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
@RunWith(Parameterized.class) | ||
public class GeoPointGenericFieldIT { | ||
|
||
@Parameterized.Parameters(name = "{0}") | ||
public static Object[] backendConfigurations() { | ||
return BackendConfigurations.simple().toArray(); | ||
} | ||
|
||
@Rule | ||
public OrmSetupHelper setupHelper; | ||
|
||
private EntityManagerFactory entityManagerFactory; | ||
|
||
public GeoPointGenericFieldIT(BackendConfiguration backendConfiguration) { | ||
this.setupHelper = OrmSetupHelper.withSingleBackend( backendConfiguration ); | ||
} | ||
|
||
@Before | ||
public void setup() { | ||
entityManagerFactory = setupHelper.start() | ||
.withProperty( | ||
HibernateOrmMapperSettings.AUTOMATIC_INDEXING_SYNCHRONIZATION_STRATEGY, | ||
AutomaticIndexingSynchronizationStrategyName.SEARCHABLE | ||
) | ||
.setup( Author.class, MyCoordinates.class ); | ||
} | ||
|
||
@Test | ||
public void smoke() { | ||
OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> { | ||
Author author = new Author(); | ||
author.setName( "Isaac Asimov" ); | ||
author.setPlaceOfBirth( new MyCoordinates( 53.976177, 32.158627 ) ); | ||
|
||
entityManager.persist( author ); | ||
} ); | ||
|
||
OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> { | ||
SearchSession searchSession = Search.session( entityManager ); | ||
|
||
List<Author> result = searchSession.search( Author.class ) | ||
.predicate( f -> f.spatial().within().onField( "placeOfBirth" ) | ||
.circle( 53.970000, 32.150000, 50, DistanceUnit.KILOMETERS ) ) | ||
.fetchHits(); | ||
assertThat( result ).hasSize( 1 ); | ||
} ); | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
...ava/org/hibernate/search/documentation/mapper/orm/spatial/genericfield/MyCoordinates.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.documentation.mapper.orm.spatial.genericfield; | ||
|
||
import javax.persistence.Basic; | ||
import javax.persistence.Embeddable; | ||
|
||
import org.hibernate.search.engine.spatial.GeoPoint; | ||
|
||
//tag::include[] | ||
@Embeddable | ||
public class MyCoordinates implements GeoPoint { // <1> | ||
|
||
@Basic | ||
private Double latitude; | ||
|
||
@Basic | ||
private Double longitude; | ||
|
||
protected MyCoordinates() { | ||
// For Hibernate ORM | ||
} | ||
|
||
public MyCoordinates(double latitude, double longitude) { | ||
this.latitude = latitude; | ||
this.longitude = longitude; | ||
} | ||
|
||
@Override | ||
public double getLatitude() { // <2> | ||
return latitude; | ||
} | ||
|
||
@Override | ||
public double getLongitude() { | ||
return longitude; | ||
} | ||
} | ||
//end::include[] |
Oops, something went wrong.