org.hibernate.search.spatial.SpatialFieldBridgeByRange Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-search-engine Show documentation
Show all versions of hibernate-search-engine Show documentation
Core of the Object/Lucene mapper, query engine and index management
/*
* Hibernate Search, full-text search for your domain model
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or .
*/
package org.hibernate.search.spatial;
import org.apache.lucene.document.Document;
import org.hibernate.search.bridge.LuceneOptions;
import org.hibernate.search.spatial.impl.SpatialHelper;
/**
* Hibernate Search field bridge using Range Spatial, binding a Coordinates to two numeric fields for latitude and Longitude
*
* @author Nicolas Helleringer
*/
public class SpatialFieldBridgeByRange extends SpatialFieldBridge {
public SpatialFieldBridgeByRange() {
}
public SpatialFieldBridgeByRange(String latitudeField, String longitudeField) {
this.latitudeField = latitudeField;
this.longitudeField = longitudeField;
}
/**
* Actual overridden method that does the indexing
*
* @param name of the field
* @param value of the field
* @param document document being indexed
* @param luceneOptions current indexing options and accessors
*/
@Override
public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
if ( value != null ) {
Double latitude = getLatitude( value );
Double longitude = getLongitude( value );
if ( ( latitude != null ) && ( longitude != null ) ) {
luceneOptions.addNumericFieldToDocument(
SpatialHelper.formatLatitude( name ),
latitude,
document
);
luceneOptions.addNumericFieldToDocument(
SpatialHelper.formatLongitude( name ),
longitude,
document
);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy