Hello!
I have a problem with spatial search.
It seems that if you use onCoordinates on a list of objects, Hibernate Search only returns true if the first object in the list has locations that falls within the range desired.
We are using Hibernate Core 4.3.5.Final, Hibernate Commons Annotations 4.0.4.Final, Hibernate Validator 5.1.0.Final, Hibernate Search 4.5.0.Final, Lucene 3.6.2
Code Example:
Classes:
Code:
@Entity
@Indexed
public Class A {
@IndexedEmbedded
@OneToMany(mappedBy = "a", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private Set<B> listOfB = new HashSet<B>();
<snip>
}
@Entity
@Indexed
public Class B {
@ContainedIn
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE, optional = false)
@JoinColumn(name = "A_ID", referencedColumnName = "A_ID", nullable = false)
private A a;
@IndexedEmbedded
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE, optional = false)
@JoinColumn(name = "ADDRESS_ID", referencedColumnName = "ADDRESS_ID", nullable = false)
private DAddress address;
<snip>
}
@Spatial(name = "location", spatialMode = SpatialMode.RANGE)
@Entity
@Indexed
public Class DAddress {
@Latitude(of = "location")
@Column(name = "LATITUDE")
private Double latitude;
@Longitude(of = "location")
@Column(name = "LONGITUDE")
private Double longitude;
<snip>
}
Hibernate Search query:
Code:
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(this.getEntityManager());
QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(A.class).get();
BooleanJunction<BooleanJunction> bool = queryBuilder.bool();
<snip some checks on other fields>
if (referencepoint != null) {
double maxDistanceInKm = (double) maxDistance / KM;
bool.must(queryBuilder
.spatial()
.onCoordinates("listOfB.address.location")
.within(maxDistanceInKm, Unit.KM)
.ofLatitude(referencepoint.getLatitude())
.andLongitude(referencepoint.getLongitude())
.createQuery());
}
Here it seems that I only get a result if the first object in listOfB.address.location matches the latitude/longitude criteria.
If one of the following objects in the list matches, I still won't get a resutlt.
Have I missed something?
Isn't is possible to do spatial search in lists?
Regards
Andreas