It's doable by setting the max results number and ordering the results by distance. E.g. like so:
Code:
final QueryBuilder builder = fullTextSession.getSearchFactory()
.buildQueryBuilder().forEntity( Store.class ).get();
org.apache.lucene.search.Query luceneQuery = builder.spatial().onField( "location" )
.within( 20.0, Unit.KM ).ofLatitude( centerLatitude ).andLongitude( centerLongitude )
.createQuery();
org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery( luceneQuery, Store.class )
.setMaxResults( 10 )
.setSort( new Sort( new DistanceSortField(centerLatitude, centerLongitude, "location") ) );
List results = hibQuery.list();
You still need to set a radius via within(). Either set it to a sufficiently large value to consider all locations or incrementally increase it in case you don't get back enough results.
Hth,
--Gunnar