diff --git a/redis-om-spring/src/main/java/com/redis/om/spring/repository/support/SimpleRedisDocumentRepository.java b/redis-om-spring/src/main/java/com/redis/om/spring/repository/support/SimpleRedisDocumentRepository.java index 7e910096..0bdcad0b 100644 --- a/redis-om-spring/src/main/java/com/redis/om/spring/repository/support/SimpleRedisDocumentRepository.java +++ b/redis-om-spring/src/main/java/com/redis/om/spring/repository/support/SimpleRedisDocumentRepository.java @@ -403,25 +403,10 @@ public Page findAll(Example example, Pageable pageable) { SearchStream stream = entityStream.of(example.getProbeType()); var offset = pageable.getPageNumber() * pageable.getPageSize(); var limit = pageable.getPageSize(); - Slice slice = stream.filter(example).loadAll().limit(limit, Math.toIntExact(offset)) + Page page = stream.filter(example).loadAll().limit(limit, Math.toIntExact(offset)) .toList(pageable, stream.getEntityClass()); - if (indexer.indexDefinitionExistsFor(metadata.getJavaType())) { - String searchIndex = indexer.getIndexName(metadata.getJavaType()); - - SearchOperations searchOps = modulesOperations.opsForSearch(searchIndex); - Query query = new Query(stream.backingQuery()); - query.setNoContent(); - - for (Order order : pageable.getSort()) { - query.setSortBy(order.getProperty(), order.isAscending()); - } - - SearchResult searchResult = searchOps.search(query); - return pageFromSlice(slice, searchResult.getTotalResults(), pageable.getPageSize()); - } else { - return pageFromSlice(slice); - } + return page; } /* (non-Javadoc) diff --git a/redis-om-spring/src/main/java/com/redis/om/spring/repository/support/SimpleRedisEnhancedRepository.java b/redis-om-spring/src/main/java/com/redis/om/spring/repository/support/SimpleRedisEnhancedRepository.java index dbcadb76..870a08f6 100644 --- a/redis-om-spring/src/main/java/com/redis/om/spring/repository/support/SimpleRedisEnhancedRepository.java +++ b/redis-om-spring/src/main/java/com/redis/om/spring/repository/support/SimpleRedisEnhancedRepository.java @@ -49,7 +49,6 @@ import java.util.stream.Collectors; import java.util.stream.StreamSupport; -import static com.redis.om.spring.RedisOMProperties.MAX_SEARCH_RESULTS; import static com.redis.om.spring.util.ObjectUtils.*; public class SimpleRedisEnhancedRepository extends SimpleKeyValueRepository @@ -405,25 +404,10 @@ public Page findAll(Example example, Pageable pageable) { SearchStream stream = entityStream.of(example.getProbeType()); var offset = pageable.getPageNumber() * pageable.getPageSize(); var limit = pageable.getPageSize(); - Slice slice = stream.filter(example).loadAll().limit(limit, Math.toIntExact(offset)) + Page page = stream.filter(example).loadAll().limit(limit, Math.toIntExact(offset)) .toList(pageable, stream.getEntityClass()); - if (indexer.indexDefinitionExistsFor(metadata.getJavaType())) { - String searchIndex = indexer.getIndexName(metadata.getJavaType()); - - SearchOperations searchOps = modulesOperations.opsForSearch(searchIndex); - Query query = new Query(stream.backingQuery()); - query.setNoContent(); - - for (Order order : pageable.getSort()) { - query.setSortBy(order.getProperty(), order.isAscending()); - } - - SearchResult searchResult = searchOps.search(query); - return pageFromSlice(slice, searchResult.getTotalResults(), pageable.getPageSize()); - } else { - return pageFromSlice(slice); - } + return page; } @Override diff --git a/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/AggregationPage.java b/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/AggregationPage.java index 0f9a3eb3..6c7a5077 100644 --- a/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/AggregationPage.java +++ b/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/AggregationPage.java @@ -2,9 +2,13 @@ import com.google.gson.Gson; import com.redis.om.spring.convert.MappingRedisOMConverter; +import com.redis.om.spring.ops.search.SearchOperations; import com.redis.om.spring.util.ObjectUtils; import org.springframework.data.domain.*; +import org.springframework.data.domain.Sort.Order; import org.springframework.util.Assert; +import redis.clients.jedis.search.Query; +import redis.clients.jedis.search.SearchResult; import redis.clients.jedis.search.aggr.AggregationResult; import java.io.Serializable; @@ -12,29 +16,32 @@ import java.util.List; import java.util.function.Function; -public class AggregationPage implements Slice, Serializable { +public class AggregationPage implements Page, Serializable { private final transient Pageable pageable; private final transient Gson gson; private final Class entityClass; private final boolean isDocument; private final transient MappingRedisOMConverter mappingConverter; + private final SearchOperations search; private List content; private transient AggregationStream aggregationStream; private long cursorId = -1; private AggregationResult aggregationResult; + private Long totalElementCount; public AggregationPage(AggregationStream aggregationStream, Pageable pageable, Class entityClass, Gson gson, - MappingRedisOMConverter mappingConverter, boolean isDocument) { + MappingRedisOMConverter mappingConverter, boolean isDocument, SearchOperations search) { this.aggregationStream = aggregationStream; this.pageable = pageable; this.entityClass = entityClass; this.gson = gson; this.isDocument = isDocument; this.mappingConverter = mappingConverter; + this.search = search; } public AggregationPage(AggregationResult aggregationResult, Pageable pageable, Class entityClass, Gson gson, - MappingRedisOMConverter mappingConverter, boolean isDocument) { + MappingRedisOMConverter mappingConverter, boolean isDocument, SearchOperations search) { this.aggregationResult = aggregationResult; this.pageable = pageable; this.entityClass = entityClass; @@ -42,6 +49,7 @@ public AggregationPage(AggregationResult aggregationResult, Pageable pageable, C this.cursorId = aggregationResult.getCursorId(); this.isDocument = isDocument; this.mappingConverter = mappingConverter; + this.search = search; } @Override @@ -86,7 +94,8 @@ public boolean isLast() { @Override public boolean hasNext() { - return cursorId == -1 || resolveCursorId() != 0; + // return cursorId == -1 || resolveCursorId() != 0; + return aggregationStream != null ? getNumber() + 1 < getTotalPages() : cursorId == -1 || resolveCursorId() != 0; } @Override @@ -96,8 +105,34 @@ public Pageable nextPageable() { } @Override - public Slice map(Function converter) { - return new SliceImpl<>(getConvertedContent(converter), pageable, hasNext()); + public int getTotalPages() { + return (getTotalElements() == 0 || pageable.getPageSize() == 0) ? + 0 : + (int) Math.ceil((double) getTotalElements() / (double) pageable.getPageSize()); + } + + @Override + public long getTotalElements() { + if (totalElementCount == null) { + if (aggregationStream != null) { + String baseQuery = aggregationStream.backingQuery(); + Query countQuery = (baseQuery.isBlank()) ? new Query() : new Query(baseQuery); + countQuery.setNoContent(); + for (Order order : pageable.getSort()) { + countQuery.setSortBy(order.getProperty(), order.isAscending()); + } + SearchResult searchResult = search.search(countQuery); + totalElementCount = searchResult.getTotalResults(); + } else { + totalElementCount = aggregationResult.getTotalResults(); // not quite sure about this shit + } + } + return totalElementCount; + } + + @Override + public Page map(Function converter) { + return new PageImpl<>(getConvertedContent(converter)); } @Override diff --git a/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/AggregationStream.java b/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/AggregationStream.java index 6e37bf12..b39bbebc 100644 --- a/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/AggregationStream.java +++ b/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/AggregationStream.java @@ -3,8 +3,8 @@ import com.redis.om.spring.annotations.ReducerFunction; import com.redis.om.spring.metamodel.MetamodelField; import com.redis.om.spring.search.stream.aggregations.filters.AggregationFilter; +import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Slice; import org.springframework.data.domain.Sort.Order; import redis.clients.jedis.search.aggr.AggregationResult; @@ -50,10 +50,12 @@ public interface AggregationStream { List toList(Class... contentTypes); + String backingQuery(); + // Cursor API AggregationStream cursor(int i, Duration duration); - Slice toList(Pageable pageRequest, Class... contentTypes); + Page toList(Pageable pageRequest, Class... contentTypes); - Slice toList(Pageable pageRequest, Duration duration, Class... contentTypes); + Page toList(Pageable pageRequest, Duration duration, Class... contentTypes); } diff --git a/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/AggregationStreamImpl.java b/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/AggregationStreamImpl.java index 4a55ca2b..03461a82 100644 --- a/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/AggregationStreamImpl.java +++ b/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/AggregationStreamImpl.java @@ -10,8 +10,8 @@ import com.redis.om.spring.search.stream.aggregations.filters.AggregationFilter; import com.redis.om.spring.tuple.Tuples; import com.redis.om.spring.util.ObjectUtils; +import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Slice; import org.springframework.data.domain.Sort.Direction; import org.springframework.data.domain.Sort.Order; import org.springframework.data.redis.core.convert.ReferenceResolverImpl; @@ -34,6 +34,7 @@ public class AggregationStreamImpl implements AggregationStream { private Group currentGroup; private ReducerFieldPair currentReducer; private boolean limitSet = false; + private final String query; @SafeVarargs public AggregationStreamImpl(String searchIndex, RedisModulesOperations modulesOperations, Gson gson, @@ -42,6 +43,7 @@ public AggregationStreamImpl(String searchIndex, RedisModulesOperations search = modulesOperations.opsForSearch(searchIndex); aggregation = new AggregationBuilder(query); isDocument = entityClass.isAnnotationPresent(Document.class); + this.query = query; this.gson = gson; this.mappingConverter = new MappingRedisOMConverter(null, new ReferenceResolverImpl(modulesOperations.template())); createAggregationGroup(fields); @@ -376,6 +378,11 @@ public List toList(Class... contentTypes) { return (List) asList; } + @Override + public String backingQuery() { + return query; + } + @Override public AggregationStream cursor(int count, Duration timeout) { applyCurrentGroupBy(); @@ -387,18 +394,18 @@ public AggregationStream cursor(int count, Duration timeout) { @Override @SuppressWarnings({ "unchecked", "rawtypes" }) - public Slice toList(Pageable pageRequest, Class... contentTypes) { + public Page toList(Pageable pageRequest, Class... contentTypes) { applyCurrentGroupBy(); aggregation.cursor(pageRequest.getPageSize(), 300000); - return new AggregationPage(this, pageRequest, entityClass, gson, mappingConverter, isDocument); + return new AggregationPage(this, pageRequest, entityClass, gson, mappingConverter, isDocument, this.search); } @Override @SuppressWarnings({ "unchecked", "rawtypes" }) - public Slice toList(Pageable pageRequest, Duration timeout, Class... contentTypes) { + public Page toList(Pageable pageRequest, Duration timeout, Class... contentTypes) { applyCurrentGroupBy(); aggregation.cursor(pageRequest.getPageSize(), timeout.toMillis()); - return new AggregationPage(this, pageRequest, entityClass, gson, mappingConverter, isDocument); + return new AggregationPage(this, pageRequest, entityClass, gson, mappingConverter, isDocument, this.search); } private void applyCurrentGroupBy() { diff --git a/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/ReturnFieldsSearchStreamImpl.java b/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/ReturnFieldsSearchStreamImpl.java index 665ec109..f0c1cc66 100644 --- a/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/ReturnFieldsSearchStreamImpl.java +++ b/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/ReturnFieldsSearchStreamImpl.java @@ -15,8 +15,8 @@ import org.apache.commons.logging.LogFactory; import org.springframework.data.annotation.Id; import org.springframework.data.domain.Example; +import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Slice; import org.springframework.data.domain.Sort; import redis.clients.jedis.search.Document; import redis.clients.jedis.search.Query; @@ -454,7 +454,7 @@ public SearchOperations getSearchOperations() { } @Override - public Slice getSlice(Pageable pageable) { + public Page getPage(Pageable pageable) { throw new UnsupportedOperationException("getPage is not supported on a ReturnFieldSearchStream"); } diff --git a/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/SearchStream.java b/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/SearchStream.java index e4e17d25..5cedb406 100644 --- a/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/SearchStream.java +++ b/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/SearchStream.java @@ -6,8 +6,8 @@ import com.redis.om.spring.search.stream.predicates.SearchFieldPredicate; import com.redis.om.spring.tuple.Pair; import org.springframework.data.domain.Example; +import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Slice; import org.springframework.data.domain.Sort; import redis.clients.jedis.search.aggr.SortedField.SortOrder; @@ -118,7 +118,7 @@ public interface SearchStream extends BaseStream> { SearchOperations getSearchOperations(); - Slice getSlice(Pageable pageable); + Page getPage(Pageable pageable); SearchStream project(Function field); diff --git a/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/SearchStreamImpl.java b/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/SearchStreamImpl.java index e59b9ad7..27666ab8 100644 --- a/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/SearchStreamImpl.java +++ b/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/SearchStreamImpl.java @@ -45,7 +45,6 @@ import static com.redis.om.spring.metamodel.MetamodelUtils.getMetamodelForIdField; import static com.redis.om.spring.util.ObjectUtils.floatArrayToByteArray; -import static com.redis.om.spring.util.ObjectUtils.pageFromSlice; import static java.util.stream.Collectors.toCollection; public class SearchStreamImpl implements SearchStream { @@ -722,12 +721,12 @@ public SearchOperations getSearchOperations() { } @Override - public Slice getSlice(Pageable pageable) { + public Page getPage(Pageable pageable) { if (pageable.getClass().isAssignableFrom(AggregationPageable.class)) { resolvedStream = Stream.empty(); AggregationPageable ap = (AggregationPageable) pageable; AggregationResult ar = search.cursorRead(ap.getCursorId(), pageable.getPageSize()); - return new AggregationPage<>(ar, pageable, entityClass, getGson(), mappingConverter, isDocument); + return new AggregationPage<>(ar, pageable, entityClass, getGson(), mappingConverter, isDocument, this.search); } else { if (!isStreamResolved()) { this.sorted(pageable.getSort()).limit(pageable.getPageSize()).skip(Math.toIntExact(pageable.getOffset())); @@ -736,9 +735,9 @@ public Slice getSlice(Pageable pageable) { countQuery.limit(Math.toIntExact(pageable.getOffset() + pageable.getPageSize()), pageable.getPageSize()); SearchResult searchResult = search.search(countQuery); - return new SliceImpl<>(this.resolveStream().toList(), pageable, !searchResult.getDocuments().isEmpty()); + return new PageImpl<>(this.resolveStream().toList(), pageable, searchResult.getTotalResults()); } else { - return new SliceImpl(List.of()); + return new PageImpl(List.of()); } } diff --git a/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/WrapperSearchStream.java b/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/WrapperSearchStream.java index 697ed5d7..6d52c870 100644 --- a/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/WrapperSearchStream.java +++ b/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/WrapperSearchStream.java @@ -6,8 +6,8 @@ import com.redis.om.spring.search.stream.predicates.SearchFieldPredicate; import com.redis.om.spring.tuple.Pair; import org.springframework.data.domain.Example; +import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Slice; import org.springframework.data.domain.Sort; import redis.clients.jedis.search.aggr.SortedField.SortOrder; @@ -313,7 +313,7 @@ public SearchOperations getSearchOperations() { } @Override - public Slice getSlice(Pageable pageable) { + public Page getPage(Pageable pageable) { throw new UnsupportedOperationException("getPage is not supported on a WrappedSearchStream"); } diff --git a/redis-om-spring/src/main/java/com/redis/om/spring/util/ObjectUtils.java b/redis-om-spring/src/main/java/com/redis/om/spring/util/ObjectUtils.java index d0493676..60f47336 100644 --- a/redis-om-spring/src/main/java/com/redis/om/spring/util/ObjectUtils.java +++ b/redis-om-spring/src/main/java/com/redis/om/spring/util/ObjectUtils.java @@ -12,7 +12,7 @@ import org.springframework.core.ResolvableType; import org.springframework.core.type.filter.AnnotationTypeFilter; import org.springframework.data.annotation.Id; -import org.springframework.data.domain.*; +import org.springframework.data.domain.ExampleMatcher; import org.springframework.data.geo.Distance; import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit; import org.springframework.data.redis.core.convert.Bucket; @@ -467,94 +467,6 @@ public static String getKey(String keyspace, Object id) { return String.format(format, keyspace, id); } - public static Page pageFromSlice(Slice slice) { - return pageFromSlice(slice, Long.MAX_VALUE, slice.getPageable().getPageSize()); - } - - public static Page pageFromSlice(Slice slice, long totalElements, int pageSize) { - return new Page<>() { - @Override - public int getTotalPages() { - return (totalElements == 0 || pageSize == 0) ? 0 : (int) Math.ceil((double) totalElements / (double) pageSize); - } - - @Override - public long getTotalElements() { - return totalElements; - } - - @Override - public Page map(Function converter) { - return pageFromSlice(slice.map(converter)); - } - - @Override - public int getNumber() { - return slice.getNumber(); - } - - @Override - public int getSize() { - return slice.getSize(); - } - - @Override - public int getNumberOfElements() { - return slice.getNumberOfElements(); - } - - @Override - public List getContent() { - return slice.getContent(); - } - - @Override - public boolean hasContent() { - return slice.hasContent(); - } - - @Override - public Sort getSort() { - return slice.getSort(); - } - - @Override - public boolean isFirst() { - return getNumber() == 0; - } - - @Override - public boolean isLast() { - return getNumber() + 1 == getTotalPages(); - } - - @Override - public boolean hasNext() { - return getNumber() + 1 < getTotalPages(); - } - - @Override - public boolean hasPrevious() { - return getNumber() > 0; - } - - @Override - public Pageable nextPageable() { - return slice.nextPageable(); - } - - @Override - public Pageable previousPageable() { - return slice.previousPageable(); - } - - @Override - public Iterator iterator() { - return slice.iterator(); - } - }; - } - public static Object getValueByPath(Object target, String path) { // Remove JSONPath prefix String safeSpelPath = path.replace("$.", ""); diff --git a/redis-om-spring/src/test/java/com/redis/om/spring/search/stream/EntityStreamDocsTest.java b/redis-om-spring/src/test/java/com/redis/om/spring/search/stream/EntityStreamDocsTest.java index 70af833f..d55e5eaa 100644 --- a/redis-om-spring/src/test/java/com/redis/om/spring/search/stream/EntityStreamDocsTest.java +++ b/redis-om-spring/src/test/java/com/redis/om/spring/search/stream/EntityStreamDocsTest.java @@ -8,6 +8,7 @@ import com.redis.om.spring.fixtures.document.repository.Doc3Repository; import com.redis.om.spring.fixtures.document.repository.NiCompanyRepository; import com.redis.om.spring.fixtures.document.repository.UserRepository; +import com.redis.om.spring.repository.query.Sort; import com.redis.om.spring.tuple.Fields; import com.redis.om.spring.tuple.Pair; import com.redis.om.spring.tuple.Quad; @@ -16,9 +17,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Slice; -import com.redis.om.spring.repository.query.Sort; import org.springframework.data.geo.Distance; import org.springframework.data.geo.Metrics; import org.springframework.data.geo.Point; @@ -2767,8 +2767,8 @@ void testPageablePagination() { var page0Request = PageRequest.of(page, PAGE_SIZE, Sort.by(Company$.NAME)); // get first page - Slice page0 = entityStream.of(Company.class) // - .getSlice(page0Request); + Page page0 = entityStream.of(Company.class) // + .getPage(page0Request); assertThat(page0).hasSize(PAGE_SIZE); @@ -2780,8 +2780,8 @@ void testPageablePagination() { // get second page page = 1; var page1Request = PageRequest.of(page, PAGE_SIZE, Sort.by(Company$.NAME)); - Slice page1 = entityStream.of(Company.class) // - .getSlice(page1Request); + Page page1 = entityStream.of(Company.class) // + .getPage(page1Request); assertThat(page1).hasSize(1); assertThat(page1.hasNext()).isFalse(); diff --git a/redis-om-spring/src/test/java/com/redis/om/spring/search/stream/EntityStreamHashTest.java b/redis-om-spring/src/test/java/com/redis/om/spring/search/stream/EntityStreamHashTest.java index 489ff7b5..8bd912de 100644 --- a/redis-om-spring/src/test/java/com/redis/om/spring/search/stream/EntityStreamHashTest.java +++ b/redis-om-spring/src/test/java/com/redis/om/spring/search/stream/EntityStreamHashTest.java @@ -16,8 +16,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Slice; import org.springframework.data.geo.Distance; import org.springframework.data.geo.Metrics; import org.springframework.data.geo.Point; @@ -1774,8 +1774,8 @@ void testPageablePagination() { var page0Request = PageRequest.of(page, PAGE_SIZE, Sort.by(Company$.NAME)); // get first page - Slice page0 = entityStream.of(Company.class) // - .getSlice(page0Request); + Page page0 = entityStream.of(Company.class) // + .getPage(page0Request); assertThat(page0).hasSize(PAGE_SIZE); @@ -1787,8 +1787,8 @@ void testPageablePagination() { // get second page page = 1; var page1Request = PageRequest.of(page, PAGE_SIZE, Sort.by(Company$.NAME)); - Slice page1 = entityStream.of(Company.class) // - .getSlice(page1Request); + Page page1 = entityStream.of(Company.class) // + .getPage(page1Request); assertThat(page1).hasSize(1); assertThat(page1.hasNext()).isFalse(); diff --git a/redis-om-spring/src/test/java/com/redis/om/spring/search/stream/EntityStreamsAggregationsDocsPagingTest.java b/redis-om-spring/src/test/java/com/redis/om/spring/search/stream/EntityStreamsAggregationsDocsPagingTest.java index 3f0aa304..75b3eb24 100644 --- a/redis-om-spring/src/test/java/com/redis/om/spring/search/stream/EntityStreamsAggregationsDocsPagingTest.java +++ b/redis-om-spring/src/test/java/com/redis/om/spring/search/stream/EntityStreamsAggregationsDocsPagingTest.java @@ -8,7 +8,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Slice; import redis.clients.jedis.search.aggr.AggregationResult; import java.io.IOException; @@ -108,7 +107,7 @@ void testManagedCursorSession() { int pageSize = 45; SearchStream searchStream = entityStream.of(Game.class); - Slice page = searchStream // + Page page = searchStream // .loadAll().limit(300).toList(PageRequest.ofSize(pageSize), Game.class); // loop through the slices using the SearchStream.getSlice method passing the next page request @@ -118,7 +117,7 @@ void testManagedCursorSession() { List contents = page.getContent(); // collect the page counts pageCounts.put(page.getNumber(), contents.size()); - page = page.hasNext() ? searchStream.getSlice(page.nextPageable()) : Page.empty(); + page = page.hasNext() ? searchStream.getPage(page.nextPageable()) : Page.empty(); } // assert the page counts diff --git a/redis-om-spring/src/test/java/com/redis/om/spring/search/stream/EntityStreamsAggregationsHashPagingTest.java b/redis-om-spring/src/test/java/com/redis/om/spring/search/stream/EntityStreamsAggregationsHashPagingTest.java index 34fe2c75..4f7bfd06 100644 --- a/redis-om-spring/src/test/java/com/redis/om/spring/search/stream/EntityStreamsAggregationsHashPagingTest.java +++ b/redis-om-spring/src/test/java/com/redis/om/spring/search/stream/EntityStreamsAggregationsHashPagingTest.java @@ -10,7 +10,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Slice; import redis.clients.jedis.search.aggr.AggregationResult; import java.io.IOException; @@ -120,7 +119,7 @@ void testManagedCursorSession() { int pageSize = 45; SearchStream searchStream = entityStream.of(Game.class); - Slice page = searchStream // + Page page = searchStream // .loadAll().limit(300).toList(PageRequest.ofSize(pageSize), Game.class); // loop through the slices using the SearchStream.getSlice method passing the next page request @@ -130,7 +129,7 @@ void testManagedCursorSession() { List contents = page.getContent(); // collect the page counts pageCounts.put(page.getNumber(), contents.size()); - page = page.hasNext() ? searchStream.getSlice(page.nextPageable()) : Page.empty(); + page = page.hasNext() ? searchStream.getPage(page.nextPageable()) : Page.empty(); } // assert the page counts diff --git a/redis-om-spring/src/test/java/com/redis/om/spring/util/ObjectUtilsTest.java b/redis-om-spring/src/test/java/com/redis/om/spring/util/ObjectUtilsTest.java index 16e4c3f6..c96b3854 100644 --- a/redis-om-spring/src/test/java/com/redis/om/spring/util/ObjectUtilsTest.java +++ b/redis-om-spring/src/test/java/com/redis/om/spring/util/ObjectUtilsTest.java @@ -12,10 +12,6 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Slice; -import org.springframework.data.domain.SliceImpl; import org.springframework.data.geo.Distance; import org.springframework.data.geo.Point; import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit; @@ -344,31 +340,6 @@ void testFlattenCollection() { assertThat(flatten).containsExactly("a", "b", "c", "d", "e", "f"); } - @Test - void testPageFromSlice() { - List strings = List.of("Pantufla", "Mondongo", "Latifundio", "Alcachofa"); - List sliceContent = strings.subList(0, 2); - Slice slice = new SliceImpl<>(sliceContent); - - Page page = ObjectUtils.pageFromSlice(slice, strings.size(), 2); - - assertThat(page.getContent()).hasSize(2); - assertThat(page.getContent().get(0)).isEqualTo("Pantufla"); - assertThat(page.getNumber()).isEqualTo(slice.getNumber()); - assertThat(page.getSize()).isEqualTo(slice.getSize()); - assertThat(page.getNumberOfElements()).isEqualTo(slice.getNumberOfElements()); - assertThat(page.getSort()).isEqualTo(slice.getSort()); - assertThat(page.hasContent()).isEqualTo(slice.hasContent()); - assertThat(page.hasNext()).isEqualTo(true); - assertThat(page.hasPrevious()).isEqualTo(false); - assertThat(page.isFirst()).isEqualTo(true); - assertThat(page.isLast()).isEqualTo(false); - assertThat(page.nextPageable()).isEqualTo(slice.nextPageable()); - assertThat(page.previousPageable()).isEqualTo(slice.previousPageable()); - assertThat(page.getTotalPages()).isEqualTo(2); - assertThat(page.getPageable()).isEqualTo(Pageable.ofSize(2)); - assertThat(page.getTotalElements()).isEqualTo(4); - } @Test public void testEmptyString() {