"Locations"- Spatial 엔터티의 목록 (Set)에 @OneToMany 관계가있는 엔터티 "Message"가 있습니다 (메시지는 여러 위치를 가질 수 있습니다. 수업 아래). Luke와 같이 색인이 올바르게 작성됩니다. 두 개의 "필수"규칙이있는 복합 쿼리를 만들려고 할 때 올바른 위치 중 하나가 제공된 경우에만 쿼리가 요청 된 메시지를 반환합니다. onDefaultCoordinates()가 목록에있는 위치 중 하나만 사용하는 것과 같습니다. 그건 이해가 되겠지만, 각 좌표 세트의 이름을 가지고리스트를 만들 수 없기 때문에 onCoordinates (String arg)를 사용할 수 없습니다.최대 절전 모드 검색 (4.5) @Spatial as @IndexedEmbedded
//Message class
@Entity
@Indexed
public class Message {
private int id;
private String title;
private String content;
private Set<Location> locations;
@OneToMany(mappedBy="message", fetch=FetchType.EAGER, cascade=CascadeType.ALL)
@IndexedEmbedded
public Set<Location> getLocations(){
return locations;
}
// Rest of the getters/setters
및 위치 클래스 :
// Location class, @latitude, @longitude, omitted here, set at the getters
@Spatial (spatialMode = SpatialMode.GRID)
@Indexed
@Entity
public class Location {
private int id;
private String name;
private double latitude;
private double longitude;
private Message message;
@JsonBackReference // used in REST response -- irrelevant here
@ContainedIn
@ManyToOne
public Message getMessage() {
return message;
}
// Rest of the getters/setters
내가 .must와 메시지 클래스를 쿼리 (지정된 타이틀 여기
org.apache.lucene.search.Query luceneQuery = builder.bool()
.must(builder.keyword().onField("title").matching(text).createQuery())
.must(builder.spatial().onDefaultCoordinates().within(5, Unit.KM)
.ofLatitude(location.getLatitude()).andLongitude(location.getLongitude())
.createQuery())
.createQuery();
은 클래스입니다 : 여기 쿼리입니다) 그리고 두 번째 좌표 집합이 있어야합니다. 클래스를 응답으로받습니다 (비록 특정 위치 만 원하지만, 이것은 다른 질문입니다). 만약 내가 다른 위치 (또한 인덱스에 존재)와 같은 일을한다면 나는 빈 응답을 얻는다. 모든 아이디어 ??