use of org.hibernate.search.engine.spatial.GeoPoint in project hibernate-search by hibernate.
the class DistanceSearchProjectionComplexCasesIT method withDistanceSort.
/**
* See also {@link DistanceSearchProjectionSingleValuedBaseIT#sortable_withSort()}.
* <p>
* The main difference is that we're composing multiple sorts here.
*/
@Test
public void withDistanceSort() {
StubMappingScope scope = mainIndex.createScope();
GeoPoint center = GeoPoint.of(45.749828, 4.854172);
assertThatQuery(scope.query().select(f -> f.distance("geoPoint", center)).where(f -> f.matchAll()).sort(f -> f.distance("geoPoint", GeoPoint.of(43.749828, 1.854172)).then().distance("geoPoint", center)).toQuery()).hits().asIs().usingElementComparator(APPROX_M_COMPARATOR).containsExactly(1300d, 430d, 2730d, null);
}
use of org.hibernate.search.engine.spatial.GeoPoint in project hibernate-search by hibernate.
the class DistanceSearchProjectionComplexCasesIT method several.
/**
* See also {@link DistanceSearchProjectionSingleValuedBaseIT#several()}.
* <p>
* The main difference is that we're targeting multiple fields here.
*/
@Test
public void several() {
StubMappingScope scope = mainIndex.createScope();
ListAssert<List<?>> hitsAssert = assertThatQuery(scope.query().select(f -> f.composite(f.distance("geoPoint", GeoPoint.of(45.749828, 4.854172)), f.distance("geoPoint", GeoPoint.of(45.763363, 4.833527)), f.distance("geoPoint_1", GeoPoint.of(45.749828, 4.854172)).unit(DistanceUnit.KILOMETERS))).where(f -> f.matchAll()).sort(f -> f.field("string").missing().last().asc()).toQuery()).hits().asIs();
hitsAssert.extracting(tuple -> (Double) tuple.get(0)).usingElementComparator(APPROX_M_COMPARATOR).containsExactlyInAnyOrder(430d, 1300d, 2730d, null);
hitsAssert.extracting(tuple -> (Double) tuple.get(1)).usingElementComparator(APPROX_M_COMPARATOR).containsExactlyInAnyOrder(1780d, 1095d, 812d, null);
hitsAssert.extracting(tuple -> (Double) tuple.get(2)).usingElementComparator(APPROX_KM_COMPARATOR).containsExactlyInAnyOrder(135.834, 136.294, 134.967, null);
}
use of org.hibernate.search.engine.spatial.GeoPoint in project hibernate-search by hibernate.
the class ElasticsearchDistanceToFieldProjection method computeDistanceWithUnit.
private Double computeDistanceWithUnit(JsonElement geoPoint) {
GeoPoint decoded = CODEC.decode(geoPoint);
if (decoded == null) {
return null;
}
double distanceInMeters = SloppyMath.haversinMeters(center.latitude(), center.longitude(), decoded.latitude(), decoded.longitude());
return unit.fromMeters(distanceInMeters);
}
use of org.hibernate.search.engine.spatial.GeoPoint in project hibernate-search by hibernate.
the class SearchQueryResultLoadingOrTransformingIT method initData.
private void initData() {
index.bulkIndexer().add(MAIN_ID, document -> {
document.addValue(index.binding().string, STRING_VALUE);
document.addValue(index.binding().string_analyzed, STRING_ANALYZED_VALUE);
document.addValue(index.binding().integer, INTEGER_VALUE);
document.addValue(index.binding().localDate, LOCAL_DATE_VALUE);
document.addValue(index.binding().geoPoint, GEO_POINT_VALUE);
// Note: this object must be single-valued for these tests
DocumentElement flattenedObject = document.addObject(index.binding().flattenedObject.self);
flattenedObject.addValue(index.binding().flattenedObject.string, FLATTENED_OBJECT_STRING_VALUE);
flattenedObject.addValue(index.binding().flattenedObject.integer, FLATTENED_OBJECT_INTEGER_VALUE);
// Note: this object must be single-valued for these tests
DocumentElement nestedObject = document.addObject(index.binding().nestedObject.self);
nestedObject.addValue(index.binding().nestedObject.string, NESTED_OBJECT_STRING_VALUE);
nestedObject.addValue(index.binding().nestedObject.integer, NESTED_OBJECT_INTEGER_VALUE);
}).add(EMPTY_ID, document -> {
}).join();
}
use of org.hibernate.search.engine.spatial.GeoPoint in project hibernate-search by hibernate.
the class DistanceProjectionComplexCasesIT method several.
/**
* See also {@link DistanceProjectionSingleValuedBaseIT#several()}.
* <p>
* The main difference is that we're targeting multiple fields here.
*/
@Test
public void several() {
StubMappingScope scope = mainIndex.createScope();
ListAssert<List<?>> hitsAssert = assertThatQuery(scope.query().select(f -> f.composite(f.distance("geoPoint", GeoPoint.of(45.749828, 4.854172)), f.distance("geoPoint", GeoPoint.of(45.763363, 4.833527)), f.distance("geoPoint_1", GeoPoint.of(45.749828, 4.854172)).unit(DistanceUnit.KILOMETERS))).where(f -> f.matchAll()).sort(f -> f.field("string").missing().last().asc()).toQuery()).hits().asIs();
hitsAssert.extracting(tuple -> (Double) tuple.get(0)).usingElementComparator(APPROX_M_COMPARATOR).containsExactlyInAnyOrder(430d, 1300d, 2730d, null);
hitsAssert.extracting(tuple -> (Double) tuple.get(1)).usingElementComparator(APPROX_M_COMPARATOR).containsExactlyInAnyOrder(1780d, 1095d, 812d, null);
hitsAssert.extracting(tuple -> (Double) tuple.get(2)).usingElementComparator(APPROX_KM_COMPARATOR).containsExactlyInAnyOrder(135.834, 136.294, 134.967, null);
}
Aggregations