Skip to content

Commit eab7aae

Browse files
committedMay 16, 2025
Add support for returning SearchResult from repository query methods.
Closes: #4960
1 parent d850b9e commit eab7aae

File tree

56 files changed

+2047
-104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2047
-104
lines changed
 

‎spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ <T, R> GeoResults<R> doGeoNear(NearQuery near, Class<?> domainType, String colle
10791079
result.add(geoResult);
10801080
}
10811081

1082-
Distance avgDistance = new Distance(
1082+
Distance avgDistance = Distance.of(
10831083
result.size() == 0 ? 0 : aggregate.divide(new BigDecimal(result.size()), RoundingMode.HALF_UP).doubleValue(),
10841084
near.getMetric());
10851085

@@ -2688,7 +2688,9 @@ protected <S, T> List<T> doFind(String collectionName,
26882688

26892689
if (LOGGER.isDebugEnabled()) {
26902690

2691-
Document mappedSort = preparer instanceof SortingQueryCursorPreparer sqcp ? getMappedSortObject(sqcp.getSortObject(), entity) : null;
2691+
Document mappedSort = preparer instanceof SortingQueryCursorPreparer sqcp
2692+
? getMappedSortObject(sqcp.getSortObject(), entity)
2693+
: null;
26922694
LOGGER.debug(String.format("find using query: %s fields: %s sort: %s for class: %s in collection: %s",
26932695
serializeToJsonSafely(mappedQuery), mappedFields, serializeToJsonSafely(mappedSort), entityClass,
26942696
collectionName));
@@ -3623,7 +3625,7 @@ public GeoResult<T> doWith(Document object) {
36233625

36243626
T doWith = delegate.doWith(object);
36253627

3626-
return new GeoResult<>(doWith, new Distance(distance, metric));
3628+
return new GeoResult<>(doWith, Distance.of(distance, metric));
36273629
}
36283630
}
36293631

‎spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3312,7 +3312,7 @@ public Mono<GeoResult<T>> doWith(Document object) {
33123312

33133313
double distance = getDistance(object);
33143314

3315-
return delegate.doWith(object).map(doWith -> new GeoResult<>(doWith, new Distance(distance, metric)));
3315+
return delegate.doWith(object).map(doWith -> new GeoResult<>(doWith, Distance.of(distance, metric)));
33163316
}
33173317

33183318
double getDistance(Document object) {

0 commit comments

Comments
 (0)
Please sign in to comment.