我有一个实体" message“,它与一个" locations”列表(集合)有一个@OneToMany关系--一个Spatial实体(一个消息可能有很多个位置--参见下面的类)。索引创建正确,就像使用Luke所看到的那样。当我尝试创建具有两个“必须”规则的复合查询时,查询仅在给出一个正确的位置时才返回请求的消息。这就像onDefaultCoordinates()只接受列表中的一个位置。这很有意义,但我不能使用onCoordinates(String arg),因为无法创建具有每组坐标名称的列表。下面是查询:
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类:
// 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 (给定标题)查询message类并对第二组坐标执行.must时,将获得该类作为响应(尽管我只想要特定的位置,但这是一个不同的问题)。如果我用不同的位置(也存在于索引中)做同样的事情,我会得到一个空的响应。有什么想法吗?
发布于 2014-03-10 19:46:46
搜索没有提供任何答案,所以最后的唯一方法就是反过来做。
因此,实际上我已经交换了@IndexedEmbedded和@ContainedIn的位置,以便索引的实体地址包含消息。我不知道Search是否不提供对空间实体集的索引,或者是否需要一个特定的@SpatialBridge来迭代每一组坐标。
https://stackoverflow.com/questions/22246735
复制相似问题