Hibernate 4를 연동했다는 전제에 설명을 하겠습니다.~!
1. pom.xml파일
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search</artifactId>
<version>4.4.2.Final</version>
</dependency>
2. 모델 설정하기~!
@Entity
@Spatial
@Indexed
@Table (name = "db tableName~!")
public class SomeThing {
public int getmId() {
return mId;
}
public void setmId(int mId) {
this.mId = mId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Double getLastLongitude() {
return lastLongitude;
}
public void setLastLongitude(Double lastLongitude) {
this.lastLongitude = lastLongitude;
}
public Double getLastLatitude() {
return lastLatitude;
}
public void setLastLatitude(Double lastLatitude) {
this.lastLatitude = lastLatitude;
}
@Id
@Column (name = "id")
@GeneratedValue
private Integer mId;
@Column (name = "name")
private String name;
@Column (name = "last_latitude")
@Latitude
private Double lastLatitude;
@Column (name = "last_longitude")
@Longitude
private Double lastLongitude;
}
3. 사용하기
List<SomeThing> resultList = null;
try {
final FullTextSession fullTextSession = Search.getFullTextSession(this.mSessionFactory.getCurrentSession());
fullTextSession.createIndexer().startAndWait();
final QueryBuilder builder = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(SomeThing.class).get();
final org.apache.lucene.search.Query searchQuery = builder.spatial()
.onDefaultCoordinates()
.within(range, Unit.KM)
.ofLatitude(latitude)
.andLongitude(longitude)
.createQuery();
final FullTextQuery hibQuery = fullTextSession.createFullTextQuery(searchQuery, SomeThing.class);
resultList = hibQuery.list();
} catch (InterruptedException e) {
e.printStackTrace();
}
'Development > Web & Server' 카테고리의 다른 글
[MongoDB] List에 있는 Object의 특정값에 맞는 값 가져오기~! (Spring Data) (0) | 2013.12.31 |
---|---|
[MYSQL] utf-8 설정하기~! (0) | 2013.12.29 |
[Spring Framework] Hibernate 4 연동하기 (0) | 2013.12.25 |
[Hibernate] Many To One (0) | 2013.12.24 |
[Spring Framework] MongoDB를 이용하여 좌표검색하기~! (0) | 2013.12.23 |