首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Hibernate search (4.5) @Spatial as @IndexedEmbedded

Hibernate search (4.5) @Spatial as @IndexedEmbedded
EN

Stack Overflow用户
提问于 2014-03-07 17:51:38
回答 1查看 293关注 0票数 0

我有一个实体" message“,它与一个" locations”列表(集合)有一个@OneToMany关系--一个Spatial实体(一个消息可能有很多个位置--参见下面的类)。索引创建正确,就像使用Luke所看到的那样。当我尝试创建具有两个“必须”规则的复合查询时,查询仅在给出一个正确的位置时才返回请求的消息。这就像onDefaultCoordinates()只接受列表中的一个位置。这很有意义,但我不能使用onCoordinates(String arg),因为无法创建具有每组坐标名称的列表。下面是查询:

代码语言:javascript
复制
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();

以下是类:

代码语言:javascript
复制
//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类:

代码语言:javascript
复制
// 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时,将获得该类作为响应(尽管我只想要特定的位置,但这是一个不同的问题)。如果我用不同的位置(也存在于索引中)做同样的事情,我会得到一个空的响应。有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2014-03-10 19:46:46

搜索没有提供任何答案,所以最后的唯一方法就是反过来做。

因此,实际上我已经交换了@IndexedEmbedded@ContainedIn的位置,以便索引的实体地址包含消息。我不知道Search是否不提供对空间实体集的索引,或者是否需要一个特定的@SpatialBridge来迭代每一组坐标。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22246735

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档