/** * Returns a Lucene query to match documents by distance to a center, * relying only on spatial hashes. * * @param center center of the search discus * @param radius distance max to center in km * @param fieldName name of the Lucene Field implementing Coordinates * @return Lucene Query to be used in a search * * @see org.apache.lucene.search.Query * @see org.hibernate.search.spatial.Coordinates */ public static Query buildSpatialHashQuery(Coordinates center, double radius, String fieldName) { int bestSpatialHashLevel = SpatialHelper.findBestSpatialHashLevelForSearchRange( 2.0d * radius ); if ( bestSpatialHashLevel > SpatialFieldBridgeByHash.DEFAULT_BOTTOM_SPATIAL_HASH_LEVEL ) { bestSpatialHashLevel = SpatialFieldBridgeByHash.DEFAULT_BOTTOM_SPATIAL_HASH_LEVEL; } List<String> spatialHashCellsIds = SpatialHelper.getSpatialHashCellsIds( center, radius, bestSpatialHashLevel ); return new SpatialHashQuery( spatialHashCellsIds, SpatialHelper.formatFieldName( bestSpatialHashLevel, fieldName ) ); }
/** * Returns a Lucene query to match documents by distance to a center, * relying only on spatial hashes. * * @param center center of the search discus * @param radius distance max to center in km * @param fieldName name of the Lucene Field implementing Coordinates * @return Lucene Query to be used in a search * * @see org.apache.lucene.search.Query * @see org.hibernate.search.spatial.Coordinates */ public static Query buildSpatialHashQuery(Coordinates center, double radius, String fieldName) { int bestSpatialHashLevel = SpatialHelper.findBestSpatialHashLevelForSearchRange( 2.0d * radius ); if ( bestSpatialHashLevel > SpatialFieldBridgeByHash.DEFAULT_BOTTOM_SPATIAL_HASH_LEVEL ) { bestSpatialHashLevel = SpatialFieldBridgeByHash.DEFAULT_BOTTOM_SPATIAL_HASH_LEVEL; } List<String> spatialHashCellsIds = SpatialHelper.getSpatialHashCellsIds( center, radius, bestSpatialHashLevel ); return new SpatialHashQuery( spatialHashCellsIds, SpatialHelper.formatFieldName( bestSpatialHashLevel, fieldName ) ); }
public boolean projectedBoundingBoxCellsIdsInclusionTest( Point center, Double radius) { Integer spatialHashLevel = SpatialHelper.findBestSpatialHashLevelForSearchRange( radius ); List<String> cellsIds = SpatialHelper.getSpatialHashCellsIds( center, radius, spatialHashLevel ); Point edge = null; boolean validated = true; for ( int heading = 0; heading < 360; heading++ ) { edge = center.computeDestination( radius, heading ); String cellId = SpatialHelper.getSpatialHashCellId( edge, spatialHashLevel ); validated &= cellsIds.contains( cellId ); } return validated; }
spatialHashCellsIds = getSpatialHashCellsIds( Point.fromDegreesInclusive( lowerLeftLatitude, lowerLeftLongitude ), Point.fromDegreesInclusive( upperRightLatitude, GeometricConstants.LONGITUDE_DEGREE_RANGE / 2 ), ); spatialHashCellsIds.addAll( getSpatialHashCellsIds( Point.fromDegreesInclusive( lowerLeftLatitude, return getSpatialHashCellsIds( Point.fromDegreesInclusive( lowerLeftLatitude, lowerLeftLongitude ), Point.fromDegreesInclusive( upperRightLatitude, upperRightLongitude ),
spatialHashCellsIds = getSpatialHashCellsIds( Point.fromDegreesInclusive( lowerLeftLatitude, lowerLeftLongitude ), Point.fromDegreesInclusive( upperRightLatitude, GeometricConstants.LONGITUDE_DEGREE_RANGE / 2 ), ); spatialHashCellsIds.addAll( getSpatialHashCellsIds( Point.fromDegreesInclusive( lowerLeftLatitude, return getSpatialHashCellsIds( Point.fromDegreesInclusive( lowerLeftLatitude, lowerLeftLongitude ), Point.fromDegreesInclusive( upperRightLatitude, upperRightLongitude ),