Hibernate search (4.5) @Spatial as @IndexedEmbedded

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

Answers


Searching didn't provide any answer, so the only way to do it in the end is to do it the other way around..

So actually I've switched places of @IndexedEmbedded and @ContainedIn in order for the indexed entity Address to contain the messages. I'm not aware if Search doesn't provide indexing to Sets of spatial entities, or there is the need of a specific @SpatialBridge that iterates through every set of coordinates.


Need Your Help

How to get the Filename in code behind on selecting a file, before uploading it to the server using aspx and CS? & using spl tech if required any

c# asp.net visual-studio-2010 sharepoint-2010

I want to retrieve the file name and perform some validation on that filename. so before uploading i have to get the filename of the file selected for uploading.

xlwt and xlutils not working while xlrd works all right

python excel importerror xlwt xlutils

I am a Windows user and I have a Python 2.7 version. I would be really grateful if someone helped me on that: I have downloaded, unpacked with 7Zip and installed xlrd, xlwt and xlutils (the install...