0

I have an entity "Message" which has a @OneToMany relationship to a list (Set) of "Locations" - a Spatial entity (A message might have many locations --see below the classes). The index is created correctly, as seen with Luke. When i try to create a composite query, having two "must" rules, the query returns the requested message only when one of the correct locations is given. It's like the onDefaultCoordinates() takes only one of the locations in the list. It makes sense, but I cannot use onCoordinates(String arg) because the list cannot be created having names for each set of coordinates. Here is the query:

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();

Here are the classes:

//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

and the location class:

// 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

When I query the message class with .must(a given title) and .must the second set of coordinates, i get the class as a response (even though i would like only the specific location, but this is a different question). If i make the same thing with a different location (also present in the index) i get an empty response. Any ideas??

4

1 回答 1

0

搜索没有提供任何答案,所以最终做到这一点的唯一方法就是反其道而行之。

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

于 2014-03-10T11:46:46.207 回答