我有一個實體「消息」,它具有@OneToMany關係到「位置」的列表(Set) - 一個空間實體(一個消息可能有很多位置 - 請參見在類下面)。正如盧克所見,索引創建正確。 當我嘗試創建具有兩個「必須」規則的組合查詢時,只有在給出正確位置之一時,查詢纔會返回請求的消息。這就像onDefaultCoordinates()只需要列表中的一個位置。它是有道理的,但我不能使用onCoordinates(String arg),因爲不能爲每組座標創建名稱。 下面是查詢:Hibernate搜索(4.5)@Spatial as @IndexedEmbedded
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();
下面是類:
//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
當我查詢與。必須消息類別(在給定標題)和。第二組座標,我得到類作爲迴應(即使我只想具體的位置,但這是一個不同的問題)。如果我用不同的位置(也存在於索引中)做同樣的事情,我會得到一個空的答覆。 任何想法??