2014-03-07 42 views
0

我有一個實體「消息」,它具有@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 

當我查詢與。必須消息類別(在給定標題)和。第二組座標,我得到類作爲迴應(即使我只想具體的位置,但這是一個不同的問題)。如果我用不同的位置(也存在於索引中)做同樣的事情,我會得到一個空的答覆。 任何想法??

回答

0

搜索沒有提供任何答案,所以這樣做到底的唯一方法是做它周圍的其他方式..

所以其實我已經關掉的@IndexedEmbedded@ContainedIn的地方,以便被索引的實體地址包含消息。我不知道搜索是否不提供對空間實體集合的索引,或者是否需要遍歷每組座標的特定@SpatialBridge