Skip to content

Pageable results and @Query annotation. #1844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

/**
* Utility class with helper methods for working with {@link SearchHit}.
*
*
* @author Peter-Josef Meisch
* @author Sascha Woo
* @author Roman Puchkovskiy
Expand All @@ -43,7 +43,7 @@ private SearchHitSupport() {}

/**
* unwraps the data contained in a SearchHit for different types containing SearchHits if possible
*
*
* @param result the object, list, page or whatever containing SearchHit objects
* @return a corresponding object where the SearchHits are replaced by their content if possible, otherwise the
* original object
Expand Down Expand Up @@ -86,6 +86,12 @@ public static Object unwrapSearchHits(@Nullable Object result) {
return unwrapSearchHitsIterator((SearchHitsIterator<?>) result);
}

if (result instanceof SearchPage<?>) {
SearchPage<?> searchPage = (SearchPage<?>) result;
List<?> content = (List<?>) SearchHitSupport.unwrapSearchHits(searchPage.getSearchHits());
return new PageImpl<>(content, searchPage.getPageable(), searchPage.getTotalElements());
}

if (ReactiveWrappers.isAvailable(ReactiveWrappers.ReactiveLibrary.PROJECT_REACTOR)) {

if (result instanceof Flux) {
Expand Down Expand Up @@ -119,7 +125,7 @@ public void close() {

/**
* Builds an {@link AggregatedPage} with the {@link SearchHit} objects from a {@link SearchHits} object.
*
*
* @param searchHits, must not be {@literal null}.
* @param pageable, must not be {@literal null}.
* @return the created Page
Expand All @@ -142,7 +148,7 @@ public static <T> SearchPage<T> searchPageFor(SearchHits<T> searchHits, @Nullabl

/**
* SearchPage implementation.
*
*
* @param <T>
*/
static class SearchPageImpl<T> extends PageImpl<SearchHit<T>> implements SearchPage<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ public Object execute(Object[] parameters) {
result = elasticsearchOperations.searchOne(query, clazz, index);
}

return queryMethod.isNotSearchHitMethod() ? SearchHitSupport.unwrapSearchHits(result) : result;
return (queryMethod.isNotSearchHitMethod() && !queryMethod.isSearchPageMethod())
? SearchHitSupport.unwrapSearchHits(result)
: result;
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public void shouldExecuteCustomMethodWithQuery() {
// then
assertThat(page).isNotNull();
assertThat(page.getTotalElements()).isGreaterThanOrEqualTo(1L);
assertThat(page.getContent().get(0)).isInstanceOf(SampleEntity.class);
}

@Test
Expand Down