I'm trying to use the new functionality: Spatial Queries sorted by distance
This is my query:
Code:
final QueryBuilder builder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity( Myclass.class ).get();
double centerLatitude= lat.doubleValue();
double centerLongitude= lng.doubleValue();
Query luceneQuery = builder.spatial().onCoordinates( "location" ).within( radius, unit ).ofLatitude( centerLatitude ).andLongitude( centerLongitude ).createQuery();
FullTextQuery hibQuery = fullTextEntityManager.createFullTextQuery( luceneQuery, Myclass.class );
//begin - distanceSort block
Sort distanceSort = new Sort( new DistanceSortField( centerLatitude, centerLongitude, "location" ) );
hibQuery.setSort( distanceSort );
hibQuery.setProjection( FullTextQuery.THIS, FullTextQuery.SPATIAL_DISTANCE );
hibQuery.setSpatialParameters( centerLatitude, centerLongitude, "location" );
//end - distanceSort block
hibQuery.setFirstResult(5*index);
hibQuery.setMaxResults(5);
hibQuery.getResultList();
The code gives me this java exception On "hibQuery.getResultList()"
java.lang.ArrayIndexOutOfBoundsException: 10
at org.hibernate.search.spatial.impl.DistanceComparator.setNextReader(DistanceComparator.java:77)
at org.apache.lucene.search.TopFieldCollector$OneComparatorNonScoringCollector.setNextReader(TopFieldCollector.java:95)
at org.hibernate.search.spatial.impl.DistanceCollector.setNextReader(DistanceCollector.java:69)
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:576)
at org.hibernate.search.query.engine.impl.QueryHits.updateTopDocs(QueryHits.java:243)
at org.hibernate.search.query.engine.impl.QueryHits.<init>(QueryHits.java:144)
at org.hibernate.search.query.engine.impl.HSQueryImpl.getQueryHits(HSQueryImpl.java:457)
at org.hibernate.search.query.engine.impl.HSQueryImpl.queryEntityInfos(HSQueryImpl.java:254)
at org.hibernate.search.query.hibernate.impl.FullTextQueryImpl.list(FullTextQueryImpl.java:209)
at org.hibernate.search.jpa.impl.FullTextQueryImpl.getResultList(FullTextQueryImpl.java:160)
My query without "distanceSort block code" works very well, and gives me 2 result records.
It is my code problem or it is a hibernate search bug?