Skip to content

Commit

Permalink
HSEARCH-923 Rename to SpatialFieldBridgeByGrid and SpatialFieldBridge…
Browse files Browse the repository at this point in the history
…ByRange

Also add fieldName to parameters of SpatialFieldBridgeByRange
  • Loading branch information
emmanuelbernard authored and Sanne committed Jun 21, 2012
1 parent d075e07 commit 6c2b245
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 65 deletions.
Expand Up @@ -20,7 +20,7 @@
*/
package org.hibernate.search.annotations;

import org.hibernate.search.spatial.SpatialFieldBridge;
import org.hibernate.search.spatial.SpatialFieldBridgeByGrid;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
Expand Down Expand Up @@ -64,11 +64,11 @@
/**
* @return top range grid level for spatial indexing
*/
int topGridLevel() default SpatialFieldBridge.DEFAULT_TOP_GRID_LEVEL;
int topGridLevel() default SpatialFieldBridgeByGrid.DEFAULT_TOP_GRID_LEVEL;

/**
* @return bottom grid level for spatial indexing
*/
int bottomGridLevel() default SpatialFieldBridge.DEFAULT_BOTTOM_GRID_LEVEL;
int bottomGridLevel() default SpatialFieldBridgeByGrid.DEFAULT_BOTTOM_GRID_LEVEL;
}

Expand Up @@ -78,8 +78,8 @@
import org.hibernate.search.bridge.builtin.UUIDBridge;
import org.hibernate.search.bridge.builtin.UriBridge;
import org.hibernate.search.bridge.builtin.UrlBridge;
import org.hibernate.search.spatial.SimpleSpatialFieldBridge;
import org.hibernate.search.spatial.SpatialFieldBridge;
import org.hibernate.search.spatial.SpatialFieldBridgeByRange;
import org.hibernate.search.spatial.SpatialFieldBridgeByGrid;
import org.hibernate.search.util.logging.impl.Log;
import org.hibernate.search.util.logging.impl.LoggerFactory;

Expand Down Expand Up @@ -296,9 +296,9 @@ public static FieldBridge buildSpatialBridge( Spatial spatial, XClass clazz ) {
if ( spatial != null ) {
try {
if( spatial.spatialMode() == SpatialMode.GRID ) {
bridge = new SpatialFieldBridge( spatial.topGridLevel(), spatial.bottomGridLevel() );
bridge = new SpatialFieldBridgeByGrid( spatial.topGridLevel(), spatial.bottomGridLevel() );
} else {
bridge = new SimpleSpatialFieldBridge();
bridge = new SpatialFieldBridgeByRange();
}
}
catch ( Exception e ) {
Expand Down Expand Up @@ -340,7 +340,7 @@ else if ( numericField != null ) {
}
else if ( member.isAnnotationPresent( org.hibernate.search.annotations.Spatial.class ) ) {
Spatial spatialAnn = member.getAnnotation( org.hibernate.search.annotations.Spatial.class );
bridge= new SpatialFieldBridge( spatialAnn.topGridLevel(),
bridge = new SpatialFieldBridgeByGrid( spatialAnn.topGridLevel(),
spatialAnn.bottomGridLevel() );
}
else {
Expand Down
Expand Up @@ -20,17 +20,14 @@
*/
package org.hibernate.search.query.dsl.impl;

import org.apache.lucene.search.ConstantScoreQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.QueryWrapperFilter;

import org.hibernate.search.bridge.FieldBridge;
import org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity;
import org.hibernate.search.query.dsl.SpatialTermination;
import org.hibernate.search.spatial.SimpleSpatialFieldBridge;
import org.hibernate.search.spatial.SpatialFieldBridge;
import org.hibernate.search.spatial.SpatialFieldBridgeByRange;
import org.hibernate.search.spatial.SpatialFieldBridgeByGrid;
import org.hibernate.search.spatial.impl.Point;
import org.hibernate.search.spatial.impl.Rectangle;
import org.hibernate.search.spatial.impl.SpatialQueryBuilderFromPoint;
import org.hibernate.search.util.logging.impl.Log;
import org.hibernate.search.util.logging.impl.LoggerFactory;
Expand Down Expand Up @@ -66,8 +63,8 @@ private Query createSpatialQuery() {
// FIXME in the future we will likely react to some state stored in SpatialFieldBridge (for the indexing strategy)
String coordinatesField = spatialContext.getCoordinatesField();
FieldBridge fieldBridge = documentBuilder.getBridge( coordinatesField );
if ( fieldBridge instanceof SpatialFieldBridge ) {
return SpatialQueryBuilderFromPoint.buildSpatialQuery(
if ( fieldBridge instanceof SpatialFieldBridgeByGrid ) {
return SpatialQueryBuilderFromPoint.buildSpatialQueryByGrid(
Point.fromDegrees(
spatialContext.getCoordinates().getLatitude(),
spatialContext.getCoordinates().getLongitude()
Expand All @@ -76,13 +73,14 @@ private Query createSpatialQuery() {
coordinatesField
);
}
else if ( fieldBridge instanceof SimpleSpatialFieldBridge ) {
return SpatialQueryBuilderFromPoint.buildSimpleSpatialQuery(
else if ( fieldBridge instanceof SpatialFieldBridgeByRange ) {
return SpatialQueryBuilderFromPoint.buildSpatialQueryByRange(
Point.fromDegrees(
spatialContext.getCoordinates().getLatitude(),
spatialContext.getCoordinates().getLongitude()
),
spatialContext.getRadiusDistance() //always in KM so far, no need to convert
spatialContext.getRadiusDistance(), //always in KM so far, no need to convert
coordinatesField
);
}
else {
Expand Down
Expand Up @@ -35,7 +35,7 @@
*
* @author Nicolas Helleringer <nicolas.helleringer@novacodex.net>
*/
public class SpatialFieldBridge implements FieldBridge, ParameterizedBridge {
public class SpatialFieldBridgeByGrid implements FieldBridge, ParameterizedBridge {

public static final int DEFAULT_TOP_GRID_LEVEL = 0;
public static final int DEFAULT_BOTTOM_GRID_LEVEL = 16;
Expand All @@ -46,9 +46,9 @@ public class SpatialFieldBridge implements FieldBridge, ParameterizedBridge {
private boolean gridIndex = true;
private boolean numericFieldsIndex = true;

public SpatialFieldBridge() {}
public SpatialFieldBridgeByGrid() {}

public SpatialFieldBridge( int topGridLevel, int bottomGridLevel ) {
public SpatialFieldBridgeByGrid(int topGridLevel, int bottomGridLevel) {
this.topGridLevel = topGridLevel;
this.bottomGridLevel = bottomGridLevel;
}
Expand Down
Expand Up @@ -30,9 +30,9 @@
*
* @author Nicolas Helleringer <nicolas.helleringer@novacodex.net>
*/
public class SimpleSpatialFieldBridge implements FieldBridge {
public class SpatialFieldBridgeByRange implements FieldBridge {

public SimpleSpatialFieldBridge() {}
public SpatialFieldBridgeByRange() {}

/**
* Actual overridden method that does the indexing
Expand Down
Expand Up @@ -45,8 +45,8 @@ public abstract class SpatialQueryBuilder {
* @see Query
* @see Coordinates
*/
public static Query buildSpatialQuery(double latitude, double longitude, double radius, String fieldName) {
return SpatialQueryBuilderFromPoint.buildSpatialQuery(
public static Query buildSpatialQueryByGrid(double latitude, double longitude, double radius, String fieldName) {
return SpatialQueryBuilderFromPoint.buildSpatialQueryByGrid(
Point.fromDegrees( latitude, longitude ),
radius,
fieldName
Expand All @@ -61,16 +61,18 @@ public static Query buildSpatialQuery(double latitude, double longitude, double
* @param latitude WGS84 latitude of the center of the search
* @param longitude WGS84 longitude of the center of the search
* @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 Query
* @see Coordinates
*/
public static Query buildSimpleSpatialQuery(double latitude, double longitude, double radius) {
return SpatialQueryBuilderFromPoint.buildSimpleSpatialQuery(
public static Query buildSpatialQueryByRange(double latitude, double longitude, double radius, String fieldName) {
return SpatialQueryBuilderFromPoint.buildSpatialQueryByRange(
Point.fromDegrees( latitude, longitude ),
radius
radius,
fieldName
);
}
}
Expand Up @@ -31,11 +31,12 @@
import org.apache.lucene.search.QueryWrapperFilter;

/**
* Lucene Filter for filtering documents which have been indexed with Hibernate Search Spatial SpatialFieldBridge
* Use double lat,long field ine the index from a Coordinates field declaration
* Lucene Filter for filtering documents which have been indexed with Hibernate Search spatial Field bridge
* Use double lat,long field in the index from a Coordinates field declaration
*
* @author Nicolas Helleringer <nicolas.helleringer@novacodex.net>
* @see org.hibernate.search.spatial.SpatialFieldBridge
* @see org.hibernate.search.spatial.SpatialFieldBridgeByGrid
* @see org.hibernate.search.spatial.SpatialFieldBridgeByRange
* @see org.hibernate.search.spatial.Coordinates
*/
public final class DistanceFilter extends Filter {
Expand Down
Expand Up @@ -35,7 +35,7 @@
* Use denormalized Grid Cell Ids to return a sub set of documents near the center
*
* @author Nicolas Helleringer <nicolas.helleringer@novacodex.net>
* @see org.hibernate.search.spatial.SpatialFieldBridge
* @see org.hibernate.search.spatial.SpatialFieldBridgeByGrid
* @see org.hibernate.search.spatial.Coordinates
*/
public final class GridFilter extends Filter {
Expand Down
Expand Up @@ -21,16 +21,14 @@
package org.hibernate.search.spatial.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Grid fields,Ids generator and geometric calculation methods for use in SpatialFieldBridge
*
* @author Nicolas Helleringer <nicolas.helleringer@novacodex.net>
* @author Mathieu Perez <mathieu.perez@novacodex.net>
* @see org.hibernate.search.spatial.SpatialFieldBridge
* @see org.hibernate.search.spatial.SpatialFieldBridgeByGrid
*/
public abstract class GridHelper {

Expand Down
Expand Up @@ -29,7 +29,7 @@
import org.apache.lucene.search.Query;
import org.apache.lucene.search.QueryWrapperFilter;

import org.hibernate.search.spatial.SpatialFieldBridge;
import org.hibernate.search.spatial.SpatialFieldBridgeByGrid;

import java.util.List;

Expand All @@ -55,8 +55,8 @@ public abstract class SpatialQueryBuilderFromPoint {
*/
public static Filter buildGridFilter(Point center, double radius, String fieldName) {
int bestGridLevel = GridHelper.findBestGridLevelForSearchRange( 2.0d * radius );
if ( bestGridLevel > SpatialFieldBridge.DEFAULT_BOTTOM_GRID_LEVEL ) {
bestGridLevel = SpatialFieldBridge.DEFAULT_BOTTOM_GRID_LEVEL;
if ( bestGridLevel > SpatialFieldBridgeByGrid.DEFAULT_BOTTOM_GRID_LEVEL ) {
bestGridLevel = SpatialFieldBridgeByGrid.DEFAULT_BOTTOM_GRID_LEVEL;
}
List<String> gridCellsIds = GridHelper.getGridCellsIds( center, radius, bestGridLevel );
return new GridFilter( gridCellsIds, GridHelper.formatFieldName( bestGridLevel, fieldName ) );
Expand Down Expand Up @@ -157,7 +157,7 @@ public static Query buildDistanceQuery(Point center, double radius, String field
* @see Query
* @see org.hibernate.search.spatial.Coordinates
*/
public static Query buildSpatialQuery(Point center, double radius, String fieldName) {
public static Query buildSpatialQueryByGrid(Point center, double radius, String fieldName) {
return new ConstantScoreQuery(
buildDistanceFilter(
buildGridFilter( center, radius, fieldName ),
Expand All @@ -174,13 +174,14 @@ public static Query buildSpatialQuery(Point center, double radius, String fieldN
*
* @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 Query
* @see org.hibernate.search.spatial.Coordinates
*/
public static Query buildSimpleSpatialQuery(Point center, double radius) {
public static Query buildSpatialQueryByRange(Point center, double radius, String fieldName) {

Rectangle boundingBox = Rectangle.fromBoundingCircle( center, radius );

Expand Down
Expand Up @@ -26,14 +26,12 @@

import org.hibernate.search.annotations.Analyze;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.FieldBridge;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.NumericField;
import org.hibernate.search.annotations.Spatial;
import org.hibernate.search.annotations.Store;
import org.hibernate.search.spatial.Coordinates;
import org.hibernate.search.spatial.SpatialFieldBridge;

/**
* Hibernate Search spatial : Point Of Interest test entity
Expand Down
Expand Up @@ -15,7 +15,6 @@
import org.hibernate.search.query.facet.Facet;
import org.hibernate.search.query.facet.FacetSortOrder;
import org.hibernate.search.query.facet.FacetingRequest;
import org.hibernate.search.spatial.impl.GridHelper;
import org.hibernate.search.spatial.impl.Point;
import org.hibernate.search.spatial.impl.Rectangle;
import org.hibernate.search.spatial.impl.SpatialQueryBuilderFromPoint;
Expand Down Expand Up @@ -249,7 +248,7 @@ public static void Bench() {
}
session.clear();

luceneQuery = SpatialQueryBuilderFromPoint.buildSpatialQuery( center, radius, "location" );
luceneQuery = SpatialQueryBuilderFromPoint.buildSpatialQueryByGrid( center, radius, "location" );
hibQuery = fullTextSession.createFullTextQuery( luceneQuery, POI.class );
hibQuery.setProjection( "id", "name" );
startTime = System.nanoTime();
Expand Down Expand Up @@ -366,7 +365,7 @@ public static void FacetTest() {
Point center = Point.fromDegrees( 46, 4 );
double radius = 50.0d;

luceneQuery = SpatialQueryBuilderFromPoint.buildSpatialQuery( center, radius, "location" );
luceneQuery = SpatialQueryBuilderFromPoint.buildSpatialQueryByGrid( center, radius, "location" );
hibQuery = fullTextSession.createFullTextQuery( luceneQuery, POI.class );
hibQuery.setProjection( "id", "name", "type" );

Expand Down
@@ -1,18 +1,13 @@
package org.hibernate.search.test.spatial;

import org.hibernate.search.annotations.Analyze;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.FieldBridge;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.NumericField;
import org.hibernate.search.annotations.Spatial;
import org.hibernate.search.annotations.SpatialMode;
import org.hibernate.search.annotations.Store;
import org.hibernate.search.spatial.Coordinates;
import org.hibernate.search.spatial.SpatialFieldBridge;

import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.Id;

Expand Down
Expand Up @@ -7,7 +7,7 @@
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.NumericField;
import org.hibernate.search.annotations.Store;
import org.hibernate.search.spatial.SpatialFieldBridge;
import org.hibernate.search.spatial.SpatialFieldBridgeByGrid;
import org.hibernate.search.spatial.Coordinates;

import javax.persistence.Embedded;
Expand Down Expand Up @@ -39,7 +39,7 @@ public class POI {
double longitude;

@Field(store = Store.YES, index = Index.YES, analyze = Analyze.NO)
@FieldBridge(impl = SpatialFieldBridge.class)
@FieldBridge(impl = SpatialFieldBridgeByGrid.class)
@Embedded
public Coordinates getLocation() {
return new Coordinates() {
Expand Down

0 comments on commit 6c2b245

Please sign in to comment.