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