【问题标题】:Hibernate search (4.5) @Spatial as @IndexedEmbedded休眠搜索 (4.5) @Spatial as @IndexedEmbedded
【发布时间】:2014-03-07 09:51:38
【问题描述】:

我有一个实体“消息”,它与“位置”列表(集)具有@OneToMany 关系 - 一个空间实体(一条消息可能有许多位置 - 请参阅下面的类)。索引创建正确,如 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 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(给定标题)和 .must 第二组坐标查询消息类时,我得到类作为响应(即使我只想要特定位置,但这是一个不同的问题)。如果我在不同的位置(也存在于索引中)做同样的事情,我会得到一个空的响应。 有什么想法吗??

【问题讨论】:

    标签: java hibernate hibernate-search hibernate-spatial


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2011-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多