Pageable results and @Query annotation.

Original Pull Request #1844
Closes #1843
This commit is contained in:
Peter-Josef Meisch 2021-06-15 22:13:39 +02:00 committed by GitHub
parent 73f11a0618
commit 93cf9ab794
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 5 deletions

View File

@ -86,6 +86,12 @@ public final class SearchHitSupport {
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) {

View File

@ -126,7 +126,9 @@ public class ElasticsearchPartQuery extends AbstractElasticsearchRepositoryQuery
result = elasticsearchOperations.searchOne(query, clazz, index);
}
return queryMethod.isNotSearchHitMethod() ? SearchHitSupport.unwrapSearchHits(result) : result;
return (queryMethod.isNotSearchHitMethod() && !queryMethod.isSearchPageMethod())
? SearchHitSupport.unwrapSearchHits(result)
: result;
}
@Nullable

View File

@ -151,6 +151,7 @@ public abstract class CustomMethodRepositoryBaseTests {
// then
assertThat(page).isNotNull();
assertThat(page.getTotalElements()).isGreaterThanOrEqualTo(1L);
assertThat(page.getContent().get(0)).isInstanceOf(SampleEntity.class);
}
@Test